Skip to content

Commit 51bcb00

Browse files
authored
addresses review changes and orders commands correctly (GoogleCloudPlatform#378)
1 parent fd50405 commit 51bcb00

File tree

5 files changed

+92
-92
lines changed

5 files changed

+92
-92
lines changed

spanner/spanner.php

Lines changed: 44 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -81,112 +81,112 @@
8181
})
8282
);
8383

84-
// Create index command
85-
$application->add((new Command('create-index'))
84+
// Add column command
85+
$application->add((new Command('add-column'))
8686
->setDefinition($inputDefinition)
87-
->setDescription('Adds a simple index to the example database.')
87+
->setDescription('Adds a new column to the Albums table in the example database.')
8888
->setCode(function ($input, $output) {
89-
create_index(
89+
add_column(
9090
$input->getArgument('instance_id'),
9191
$input->getArgument('database_id')
9292
);
9393
})
9494
);
9595

96-
// Query data with index command
97-
$application->add((new Command('query-data-with-index'))
98-
->setDefinition(clone $inputDefinition)
99-
->addOption('start_title', null, InputOption::VALUE_REQUIRED, 'The start of the title index.', 'Aardvark')
100-
->addOption('end_title', null, InputOption::VALUE_REQUIRED, 'The end of the title index.', 'Goo')
101-
->setDescription('Queries sample data from the database using SQL and an index.')
96+
// Update data command
97+
$application->add((new Command('update-data'))
98+
->setDefinition($inputDefinition)
99+
->setDescription('Updates sample data in the database.')
102100
->setCode(function ($input, $output) {
103-
query_data_with_index(
101+
update_data(
104102
$input->getArgument('instance_id'),
105-
$input->getArgument('database_id'),
106-
$input->getOption('start_title'),
107-
$input->getOption('end_title')
103+
$input->getArgument('database_id')
108104
);
109105
})
110106
);
111107

112-
// Read data with index command
113-
$application->add((new Command('read-data-with-index'))
108+
// Query data with new column command
109+
$application->add((new Command('query-data-with-new-column'))
114110
->setDefinition($inputDefinition)
115-
->setDescription('Reads sample data from the database using an index.')
111+
->setDescription('Queries sample data from the database using SQL.')
116112
->setCode(function ($input, $output) {
117-
read_data_with_index(
113+
query_data_with_new_column(
118114
$input->getArgument('instance_id'),
119115
$input->getArgument('database_id')
120116
);
121117
})
122118
);
123119

124-
// Create storing index command
125-
$application->add((new Command('create-storing-index'))
120+
// Read-write transaction command
121+
$application->add((new Command('read-write-transaction'))
126122
->setDefinition($inputDefinition)
127-
->setDescription('Adds an storing index to the example database.')
123+
->setDescription('Performs a read-write transaction to update two sample records in the database.')
128124
->setCode(function ($input, $output) {
129-
create_storing_index(
125+
read_write_transaction(
130126
$input->getArgument('instance_id'),
131127
$input->getArgument('database_id')
132128
);
133129
})
134130
);
135131

136-
// Read data with storing index command
137-
$application->add((new Command('read-data-with-storing-index'))
132+
// Create index command
133+
$application->add((new Command('create-index'))
138134
->setDefinition($inputDefinition)
139-
->setDescription('Reads sample data from the database using an index with a storing clause.')
135+
->setDescription('Adds a simple index to the example database.')
140136
->setCode(function ($input, $output) {
141-
read_data_with_storing_index(
137+
create_index(
142138
$input->getArgument('instance_id'),
143139
$input->getArgument('database_id')
144140
);
145141
})
146142
);
147143

148-
// Add column command
149-
$application->add((new Command('add-column'))
150-
->setDefinition($inputDefinition)
151-
->setDescription('Adds a new column to the Albums table in the example database.')
144+
// Query data with index command
145+
$application->add((new Command('query-data-with-index'))
146+
->setDefinition(clone $inputDefinition)
147+
->addOption('start_title', null, InputOption::VALUE_REQUIRED, 'The start of the title index.', 'Aardvark')
148+
->addOption('end_title', null, InputOption::VALUE_REQUIRED, 'The end of the title index.', 'Goo')
149+
->setDescription('Queries sample data from the database using SQL and an index.')
152150
->setCode(function ($input, $output) {
153-
add_column(
151+
query_data_with_index(
154152
$input->getArgument('instance_id'),
155-
$input->getArgument('database_id')
153+
$input->getArgument('database_id'),
154+
$input->getOption('start_title'),
155+
$input->getOption('end_title')
156156
);
157157
})
158158
);
159159

160-
// Query data with new column command
161-
$application->add((new Command('query-data-with-new-column'))
160+
// Read data with index command
161+
$application->add((new Command('read-data-with-index'))
162162
->setDefinition($inputDefinition)
163-
->setDescription('Queries sample data from the database using SQL.')
163+
->setDescription('Reads sample data from the database using an index.')
164164
->setCode(function ($input, $output) {
165-
query_data_with_new_column(
165+
read_data_with_index(
166166
$input->getArgument('instance_id'),
167167
$input->getArgument('database_id')
168168
);
169169
})
170170
);
171171

172-
// Update data command
173-
$application->add((new Command('update-data'))
172+
// Create storing index command
173+
$application->add((new Command('create-storing-index'))
174174
->setDefinition($inputDefinition)
175-
->setDescription('Updates sample data in the database.')
175+
->setDescription('Adds an storing index to the example database.')
176176
->setCode(function ($input, $output) {
177-
update_data(
177+
create_storing_index(
178178
$input->getArgument('instance_id'),
179179
$input->getArgument('database_id')
180180
);
181181
})
182182
);
183183

184-
// Read-write transaction command
185-
$application->add((new Command('read-write-transaction'))
184+
// Read data with storing index command
185+
$application->add((new Command('read-data-with-storing-index'))
186186
->setDefinition($inputDefinition)
187-
->setDescription('Performs a read-write transaction to update two sample records in the database.')
187+
->setDescription('Reads sample data from the database using an index with a storing clause.')
188188
->setCode(function ($input, $output) {
189-
read_write_transaction(
189+
read_data_with_storing_index(
190190
$input->getArgument('instance_id'),
191191
$input->getArgument('database_id')
192192
);

spanner/src/query_data_with_index.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,15 +57,15 @@ function query_data_with_index($instanceId, $databaseId, $startTitle, $endTitle)
5757
];
5858

5959
$results = $database->execute(
60-
'SELECT AlbumId, AlbumTitle ' .
60+
'SELECT AlbumId, AlbumTitle, MarketingBudget ' .
6161
'FROM Albums@{FORCE_INDEX=AlbumsByAlbumTitle} ' .
6262
'WHERE AlbumTitle >= @startTitle AND AlbumTitle < @endTitle',
6363
['parameters' => $parameters]
6464
);
6565

6666
foreach ($results as $row) {
67-
printf('AlbumId: %s, AlbumTitle: %s' . PHP_EOL,
68-
$row['AlbumId'], $row['AlbumTitle']);
67+
printf('AlbumId: %s, AlbumTitle: %s, MarketingBudget: %d' . PHP_EOL,
68+
$row['AlbumId'], $row['AlbumTitle'], $row['MarketingBudget']);
6969
}
7070
}
7171
// [END query_data_with_index]

spanner/src/query_data_with_new_column.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ function query_data_with_new_column($instanceId, $databaseId)
5353
);
5454

5555
foreach ($results as $row) {
56-
printf('SingerId: %s, AlbumId: %s, MarketingBudget: %s' . PHP_EOL,
56+
printf('SingerId: %s, AlbumId: %s, MarketingBudget: %d' . PHP_EOL,
5757
$row['SingerId'], $row['AlbumId'], $row['MarketingBudget']);
5858
}
5959
}

spanner/src/read_data_with_storing_index.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ function read_data_with_storing_index($instanceId, $databaseId)
6464
);
6565

6666
foreach ($results->rows() as $row) {
67-
printf('AlbumId: %s, AlbumTitle: %s, MarketingBudget: %s' . PHP_EOL,
67+
printf('AlbumId: %s, AlbumTitle: %s, MarketingBudget: %d' . PHP_EOL,
6868
$row['AlbumId'], $row['AlbumTitle'], $row['MarketingBudget']);
6969
}
7070
}

spanner/test/spannerTest.php

Lines changed: 43 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,48 @@ public function testReadData()
109109
/**
110110
* @depends testInsertData
111111
*/
112+
public function testAddColumn()
113+
{
114+
$output = $this->runCommand('add-column');
115+
$this->assertContains('Waiting for operation to complete...', $output);
116+
$this->assertContains('Added the MarketingBudget column.', $output);
117+
}
118+
119+
/**
120+
* @depends testAddColumn
121+
*/
122+
public function testUpdateData()
123+
{
124+
$output = $this->runCommand('update-data');
125+
$this->assertEquals('Updated data.' . PHP_EOL, $output);
126+
}
127+
128+
/**
129+
* @depends testAddColumn
130+
*/
131+
public function testQueryDataWithNewColumn()
132+
{
133+
$output = $this->runCommand('query-data-with-new-column');
134+
$this->assertContains('SingerId: 1, AlbumId: 1, MarketingBudget:', $output);
135+
$this->assertContains('SingerId: 1, AlbumId: 2, MarketingBudget:', $output);
136+
$this->assertContains('SingerId: 2, AlbumId: 1, MarketingBudget:', $output);
137+
$this->assertContains('SingerId: 2, AlbumId: 2, MarketingBudget:', $output);
138+
$this->assertContains('SingerId: 2, AlbumId: 3, MarketingBudget:', $output);
139+
}
140+
141+
/**
142+
* @depends testUpdateData
143+
*/
144+
public function testReadWriteTransaction()
145+
{
146+
$output = $this->runCommand('read-write-transaction');
147+
$this->assertContains('Setting first album\'s budget to 300000 and the second album\'s budget to 300000', $output);
148+
$this->assertContains('Transaction complete.', $output);
149+
}
150+
151+
/**
152+
* @depends testAddColumn
153+
*/
112154
public function testCreateIndex()
113155
{
114156
$output = $this->runCommand('create-index');
@@ -141,30 +183,7 @@ public function testReadDataWithIndex()
141183
}
142184

143185
/**
144-
* @depends testInsertData
145-
*/
146-
public function testAddColumn()
147-
{
148-
$output = $this->runCommand('add-column');
149-
$this->assertContains('Waiting for operation to complete...', $output);
150-
$this->assertContains('Added the MarketingBudget column.', $output);
151-
}
152-
153-
/**
154-
* @depends testAddColumn
155-
*/
156-
public function testQueryDataWithNewColumn()
157-
{
158-
$output = $this->runCommand('query-data-with-new-column');
159-
$this->assertContains('SingerId: 1, AlbumId: 1, MarketingBudget:', $output);
160-
$this->assertContains('SingerId: 1, AlbumId: 2, MarketingBudget:', $output);
161-
$this->assertContains('SingerId: 2, AlbumId: 1, MarketingBudget:', $output);
162-
$this->assertContains('SingerId: 2, AlbumId: 2, MarketingBudget:', $output);
163-
$this->assertContains('SingerId: 2, AlbumId: 3, MarketingBudget:', $output);
164-
}
165-
166-
/**
167-
* @depends testAddColumn
186+
* @depends testCreateIndex
168187
*/
169188
public function testCreateStoringIndex()
170189
{
@@ -186,15 +205,6 @@ public function testReadDataWithStoringIndex()
186205
$this->assertContains('AlbumId: 2, AlbumTitle: Total Junk, MarketingBudget:', $output);
187206
}
188207

189-
/**
190-
* @depends testCreateStoringIndex
191-
*/
192-
public function testUpdateData()
193-
{
194-
$output = $this->runCommand('update-data');
195-
$this->assertEquals('Updated data.' . PHP_EOL, $output);
196-
}
197-
198208
/**
199209
* @depends testUpdateData
200210
*/
@@ -208,16 +218,6 @@ public function testReadOnlyTransaction()
208218
$this->assertContains('SingerId: 2, AlbumId: 3, AlbumTitle: Terrified', $output);
209219
}
210220

211-
/**
212-
* @depends testUpdateData
213-
*/
214-
public function testReadWriteTransaction()
215-
{
216-
$output = $this->runCommand('read-write-transaction');
217-
$this->assertContains('Setting first album\'s budget to 300000 and the second album\'s budget to 300000', $output);
218-
$this->assertContains('Transaction complete.', $output);
219-
}
220-
221221
private function runCommand($commandName)
222222
{
223223
$application = require __DIR__ . '/../spanner.php';

0 commit comments

Comments
 (0)