1Feature: Simple Statements
2
3  PHP Driver supports simple statements.
4
5  Background:
6    Given a running Cassandra cluster
7    And the following schema:
8      """cql
9      CREATE KEYSPACE simplex WITH replication = {
10        'class': 'SimpleStrategy',
11        'replication_factor': 1
12      };
13      USE simplex;
14      CREATE TABLE playlists (
15        id uuid,
16        title text,
17        album text,
18        artist text,
19        song_id uuid,
20        PRIMARY KEY (id, title, album, artist)
21      );
22      """
23
24  Scenario: Simple statements are initialized with a CQL string
25    Given the following example:
26      """php
27      <?php
28      $cluster   = Cassandra::cluster()
29                     ->withContactPoints('127.0.0.1')
30                     ->build();
31      $session   = $cluster->connect("simplex");
32      $statement = new Cassandra\SimpleStatement("SELECT * FROM playlists");
33      $result    = $session->execute($statement);
34      echo "Result contains " . $result->count() . " rows";
35      """
36    When it is executed
37    Then its output should contain:
38      """
39      Result contains 0 rows
40      """
41
42  @cassandra-version-2.0
43  Scenario: Simple statements support positional arguments
44    Given the following example:
45      """php
46      <?php
47      $cluster   = Cassandra::cluster()
48                     ->withContactPoints('127.0.0.1')
49                     ->build();
50      $session   = $cluster->connect("simplex");
51      $statement = new Cassandra\SimpleStatement(
52                     "INSERT INTO playlists (id, song_id, artist, title, album) " .
53                     "VALUES (62c36092-82a1-3a00-93d1-46196ee77204, ?, ?, ?, ?)"
54                   );
55
56      $songs = array(
57          array(
58              new Cassandra\Uuid('756716f7-2e54-4715-9f00-91dcbea6cf50'),
59              'Joséphine Baker',
60              'La Petite Tonkinoise',
61              'Bye Bye Blackbird'
62          ),
63          array(
64              new Cassandra\Uuid('f6071e72-48ec-4fcb-bf3e-379c8a696488'),
65              'Willi Ostermann',
66              'Die Mösch',
67              'In Gold'
68          ),
69          array(
70              new Cassandra\Uuid('fbdf82ed-0063-4796-9c7c-a3d4f47b4b25'),
71              'Mick Jager',
72              'Memo From Turner',
73              'Performance'
74          ),
75      );
76
77      foreach ($songs as $song) {
78          $options = array('arguments' => $song);
79          $session->execute($statement, $options);
80      }
81
82      $result = $session->execute("SELECT * FROM simplex.playlists");
83
84      foreach ($result as $row) {
85        echo $row['artist'] . ": " . $row['title'] . " / " . $row['album'] . "\n";
86      }
87      """
88    When it is executed
89    Then its output should contain:
90      """
91      Joséphine Baker: La Petite Tonkinoise / Bye Bye Blackbird
92      """
93    And its output should contain:
94      """
95      Willi Ostermann: Die Mösch / In Gold
96      """
97    And its output should contain:
98      """
99      Mick Jager: Memo From Turner / Performance
100      """
101
102  @cassandra-version-2.1
103  Scenario: Simple statements also support named arguments
104    Given the following example:
105      """php
106      <?php
107      $cluster   = Cassandra::cluster()
108                     ->withContactPoints('127.0.0.1')
109                     ->build();
110      $session   = $cluster->connect("simplex");
111      $statement = new Cassandra\SimpleStatement(
112                     "INSERT INTO playlists (id, song_id, artist, title, album) " .
113                     "VALUES (62c36092-82a1-3a00-93d1-46196ee77204, ?, ?, ?, ?)"
114                   );
115
116      $songs = array(
117          array(
118              'song_id' => new Cassandra\Uuid('756716f7-2e54-4715-9f00-91dcbea6cf50'),
119              'artist'  => 'Joséphine Baker',
120              'title'   => 'La Petite Tonkinoise',
121              'album'   => 'Bye Bye Blackbird'
122          ),
123          array(
124              'song_id' => new Cassandra\Uuid('f6071e72-48ec-4fcb-bf3e-379c8a696488'),
125              'artist'  => 'Willi Ostermann',
126              'title'   => 'Die Mösch',
127              'album'   => 'In Gold'
128          ),
129          array(
130              'song_id' => new Cassandra\Uuid('fbdf82ed-0063-4796-9c7c-a3d4f47b4b25'),
131              'artist'  => 'Mick Jager',
132              'title'   => 'Memo From Turner',
133              'album'   => 'Performance'
134          ),
135      );
136
137      foreach ($songs as $song) {
138          $session->execute($statement, array('arguments' => $song));
139      }
140
141      $result = $session->execute("SELECT * FROM simplex.playlists");
142
143      foreach ($result as $row) {
144        echo $row['artist'] . ": " . $row['title'] . " / " . $row['album'] . "\n";
145      }
146      """
147    When it is executed
148    Then its output should contain:
149      """
150      Joséphine Baker: La Petite Tonkinoise / Bye Bye Blackbird
151      """
152    And its output should contain:
153      """
154      Willi Ostermann: Die Mösch / In Gold
155      """
156    And its output should contain:
157      """
158      Mick Jager: Memo From Turner / Performance
159      """
160
161  @cassandra-version-2.1
162  Scenario: Simple statements also supports ":name" arguments
163    Given the following example:
164      """php
165      <?php
166      $cluster   = Cassandra::cluster()
167                     ->withContactPoints('127.0.0.1')
168                     ->build();
169      $session   = $cluster->connect("simplex");
170
171      $songs = array(
172          array(
173              'song_id' => new Cassandra\Uuid('756716f7-2e54-4715-9f00-91dcbea6cf50'),
174              'artist'  => 'Joséphine Baker',
175              'title'   => 'La Petite Tonkinoise',
176              'album'   => 'Bye Bye Blackbird'
177          ),
178      );
179
180      foreach ($songs as $song) {
181          $options = array('arguments' => $song);
182          $session->execute(
183              "INSERT INTO playlists (id, song_id, artist, title, album) " .
184              "VALUES (62c36092-82a1-3a00-93d1-46196ee77204, ?, ?, ?, ?)",
185              $options
186          );
187      }
188
189      $statement = new Cassandra\SimpleStatement(
190          "SELECT * FROM simplex.playlists " .
191          "WHERE id = :id AND artist = :artist AND title = :title AND album = :album"
192      );
193
194      $options = array('arguments' =>
195              array(
196                  'id'     => new Cassandra\Uuid('62c36092-82a1-3a00-93d1-46196ee77204'),
197                  'artist' => 'Joséphine Baker',
198                  'title'  => 'La Petite Tonkinoise',
199                  'album'  => 'Bye Bye Blackbird'
200              )
201      );
202
203      $result = $session->execute($statement, $options);
204
205      $row = $result->first();
206      echo $row['artist'] . ": " . $row['title'] . " / " . $row['album'] . "\n";
207      """
208    When it is executed
209    Then its output should contain:
210      """
211      Joséphine Baker: La Petite Tonkinoise / Bye Bye Blackbird
212      """
213