Skip to content

Commit 9b346e0

Browse files
authored
Merge pull request #1390 from djcvijic/master
Fix failing SQLServer tests
2 parents 9489501 + 8adf957 commit 9b346e0

File tree

4 files changed

+76
-51
lines changed

4 files changed

+76
-51
lines changed

appveyor.yml

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@ environment:
1010
TESTS_PHINX_DB_ADAPTER_SQLSRV_DATABASE: phinxtesting
1111
TESTS_PHINX_DB_ADAPTER_SQLSRV_PORT: 1433
1212
matrix:
13-
- db: 2012
13+
- dependencies: highest
14+
db: 2012
1415
php_ddl: 56_nts
1516
php_zip: php-5.6.28-nts-Win32-VC11-x86.zip
1617
db_dsn: 'sqlserver://sa:Password12!@.\SQL2012SP1/phinxtesting?MultipleActiveResultSets=false'
17-
dependencies: lowest
1818
sqlsrv: https://download.microsoft.com/download/C/D/B/CDB0A3BB-600E-42ED-8D5E-E4630C905371/SQLSRV32.EXE
1919

2020
services:
@@ -31,8 +31,8 @@ init:
3131

3232
install:
3333
- IF EXIST c:\tools\php (SET PHP=0)
34-
- appveyor DownloadFile http://windows.php.net/downloads/releases/archives/%php_zip% -FileName php.zip
35-
- appveyor DownloadFile %sqlsrv% -FileName sqlsrv.exe
34+
- curl -fsS https://windows.php.net/downloads/releases/archives/%php_zip% -o php.zip
35+
- curl -fsS %sqlsrv% -o sqlsrv.exe
3636
- 7z x php.zip -oc:\tools\php
3737
- 7z x sqlsrv.exe -oc:\tools\php\ext
3838
- cd c:\tools\php
@@ -45,11 +45,11 @@ install:
4545
- IF %PHP%==1 echo extension=php_sqlsrv_%php_ddl%.dll >> php.ini
4646
- IF %PHP%==1 echo extension=php_pdo_sqlsrv_%php_ddl%.dll >> php.ini
4747
- IF %PHP%==1 echo @php %%~dp0composer.phar %%* > composer.bat
48-
- appveyor-retry appveyor DownloadFile https://getcomposer.org/composer.phar
48+
- curl -fsS https://getcomposer.org/composer.phar -o composer.phar
4949
- cd c:\projects\phinx
50-
- IF %dependencies%==lowest appveyor-retry composer update --prefer-lowest --no-progress --profile -n
51-
- IF %dependencies%==current appveyor-retry composer install --no-progress --profile
52-
- IF %dependencies%==highest appveyor-retry composer update --no-progress --profile -n
50+
- IF %dependencies%==lowest composer update --prefer-lowest --no-progress --profile -n
51+
- IF %dependencies%==current composer install --no-progress --profile
52+
- IF %dependencies%==highest composer update --no-progress --profile -n
5353
- composer show
5454

5555
test_script:

src/Phinx/Db/Adapter/SqlServerAdapter.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,7 @@ public function getColumnComment($tableName, $columnName)
352352
$row = $this->fetchRow($sql);
353353

354354
if ($row) {
355-
return $row['comment'];
355+
return trim($row['comment']);
356356
}
357357

358358
return false;
@@ -540,7 +540,7 @@ protected function getChangeColumnInstructions($tableName, $columnName, Column $
540540
));
541541
// change column comment if needed
542542
if ($newColumn->getComment()) {
543-
$instructions->merge($this->getColumnCommentSqlDefinition($newColumn, $tableName));
543+
$instructions->addPostStep($this->getColumnCommentSqlDefinition($newColumn, $tableName));
544544
}
545545

546546
if ($changeDefault) {

tests/Phinx/Console/Command/InitTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,8 @@ public function testDefaults()
9393
$commandTester = new CommandTester($command);
9494
$commandTester->execute(['command' => $command->getName()], ['decorated' => false]);
9595
$this->assertRegExp(
96-
"/created (.*)\/phinx.yml\\n/",
97-
$commandTester->getDisplay()
96+
"/created (.*)[\/\\\\]phinx.yml\\n/",
97+
$commandTester->getDisplay(true)
9898
);
9999

100100
$this->assertFileExists(

tests/Phinx/Db/Adapter/SqlServerAdapterTest.php

Lines changed: 64 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@ public function setUp()
3939

4040
public function tearDown()
4141
{
42+
if (!empty($this->adapter)) {
43+
$this->adapter->disconnect();
44+
}
4245
unset($this->adapter);
4346
}
4447

@@ -65,6 +68,7 @@ public function testConnectionWithInvalidCredentials()
6568
'pass' => 'invalidpass'
6669
];
6770

71+
$adapter = null;
6872
try {
6973
$adapter = new SqlServerAdapter($options, new ArrayInput([]), new NullOutput());
7074
$adapter->connect();
@@ -76,6 +80,10 @@ public function testConnectionWithInvalidCredentials()
7680
'Expected exception of type InvalidArgumentException, got ' . get_class($e)
7781
);
7882
$this->assertRegExp('/There was a problem connecting to the database/', $e->getMessage());
83+
} finally {
84+
if (!empty($adapter)) {
85+
$adapter->disconnect();
86+
}
7987
}
8088
}
8189

@@ -308,21 +316,34 @@ public function testRenamingANonExistentColumn()
308316
}
309317
}
310318

311-
public function testChangeColumn()
319+
public function testChangeColumnType()
312320
{
313321
$table = new \Phinx\Db\Table('t', [], $this->adapter);
314322
$table->addColumn('column1', 'string')
315323
->save();
316324
$this->assertTrue($this->adapter->hasColumn('t', 'column1'));
317325
$newColumn1 = new \Phinx\Db\Table\Column();
318326
$newColumn1->setType('string');
319-
$table->changeColumn('column1', $newColumn1);
327+
$table->changeColumn('column1', $newColumn1)->save();
320328
$this->assertTrue($this->adapter->hasColumn('t', 'column1'));
329+
$columns = $this->adapter->getColumns('t');
330+
foreach ($columns as $column) {
331+
if ($column->getName() == 'column1') {
332+
$this->assertEquals('string', $column->getType());
333+
}
334+
}
335+
}
336+
337+
public function testChangeColumnNameAndNull()
338+
{
339+
$table = new \Phinx\Db\Table('t', [], $this->adapter);
340+
$table->addColumn('column1', 'string')
341+
->save();
321342
$newColumn2 = new \Phinx\Db\Table\Column();
322343
$newColumn2->setName('column2')
323-
->setType('string')
324-
->setNull(true);
325-
$table->changeColumn('column1', $newColumn2);
344+
->setType('string')
345+
->setNull(true);
346+
$table->changeColumn('column1', $newColumn2)->save();
326347
$this->assertFalse($this->adapter->hasColumn('t', 'column1'));
327348
$this->assertTrue($this->adapter->hasColumn('t', 'column2'));
328349
$columns = $this->adapter->getColumns('t');
@@ -347,7 +368,7 @@ public function testChangeColumnDefaults()
347368
$newColumn1
348369
->setType('string')
349370
->setDefault('another test');
350-
$table->changeColumn('column1', $newColumn1);
371+
$table->changeColumn('column1', $newColumn1)->save();
351372
$this->assertTrue($this->adapter->hasColumn('t', 'column1'));
352373

353374
$columns = $this->adapter->getColumns('t');
@@ -363,7 +384,7 @@ public function testChangeColumnDefaultToNull()
363384
$newColumn1
364385
->setType('string')
365386
->setDefault(null);
366-
$table->changeColumn('column1', $newColumn1);
387+
$table->changeColumn('column1', $newColumn1)->save();
367388
$columns = $this->adapter->getColumns('t');
368389
$this->assertNull($columns['column1']->getDefault());
369390
}
@@ -377,7 +398,7 @@ public function testChangeColumnDefaultToZero()
377398
$newColumn1
378399
->setType('string')
379400
->setDefault(0);
380-
$table->changeColumn('column1', $newColumn1);
401+
$table->changeColumn('column1', $newColumn1)->save();
381402
$columns = $this->adapter->getColumns('t');
382403
$this->assertSame(0, $columns['column1']->getDefault());
383404
}
@@ -392,34 +413,38 @@ public function testDropColumn()
392413
$this->assertFalse($this->adapter->hasColumn('t', 'column1'));
393414
}
394415

395-
public function testGetColumns()
416+
public function columnsProvider()
417+
{
418+
return [
419+
['column1', 'string', ['null' => true, 'default' => null]],
420+
['column2', 'integer', ['default' => 0]],
421+
['column3', 'biginteger', ['default' => 5]],
422+
['column4', 'text', ['default' => 'text']],
423+
['column5', 'float', []],
424+
['column6', 'decimal', []],
425+
['column7', 'time', []],
426+
['column8', 'date', []],
427+
['column9', 'boolean', []],
428+
['column10', 'datetime', []],
429+
['column11', 'binary', []],
430+
['column12', 'string', ['limit' => 10]],
431+
];
432+
}
433+
434+
/**
435+
* @dataProvider columnsProvider
436+
*/
437+
public function testGetColumns($colName, $type, $options)
396438
{
397439
$table = new \Phinx\Db\Table('t', [], $this->adapter);
398-
$table->addColumn('column1', 'string', ['null' => true, 'default' => null])
399-
->addColumn('column2', 'integer', ['default' => 0])
400-
->addColumn('column3', 'biginteger', ['default' => 5])
401-
->addColumn('column4', 'text', ['default' => 'text'])
402-
->addColumn('column5', 'float')
403-
->addColumn('column6', 'decimal')
404-
->addColumn('column7', 'time')
405-
->addColumn('column8', 'timestamp')
406-
->addColumn('column9', 'date')
407-
->addColumn('column10', 'boolean')
408-
->addColumn('column11', 'datetime')
409-
->addColumn('column12', 'binary')
410-
->addColumn('column13', 'string', ['limit' => 10]);
411-
$pendingColumns = $table->getPendingColumns();
412-
$table->save();
413-
$columns = $this->adapter->getColumns('t');
414-
$this->assertCount(count($pendingColumns) + 1, $columns);
415-
for ($i = 0; $i++; $i < count($pendingColumns)) {
416-
$this->assertEquals($pendingColumns[$i], $columns[$i + 1]);
417-
}
440+
$table
441+
->addColumn($colName, $type, $options)
442+
->save();
418443

419-
$this->assertNull($columns['column1']->getDefault());
420-
$this->assertSame(0, $columns['column2']->getDefault());
421-
$this->assertSame(5, $columns['column3']->getDefault());
422-
$this->assertSame('text', $columns['column4']->getDefault());
444+
$columns = $this->adapter->getColumns('t');
445+
$this->assertCount(2, $columns);
446+
$this->assertEquals($colName, $columns[$colName]->getName());
447+
$this->assertEquals($type, $columns[$colName]->getType());
423448
}
424449

425450
public function testAddIndex()
@@ -528,12 +553,12 @@ public function testAddForeignKey()
528553
$table->addColumn('ref_table_id', 'integer')->save();
529554

530555
$fk = new \Phinx\Db\Table\ForeignKey();
531-
$fk->setReferencedTable($refTable)
556+
$fk->setReferencedTable($refTable->getTable())
532557
->setColumns(['ref_table_id'])
533558
->setReferencedColumns(['id'])
534559
->setConstraint('fk1');
535560

536-
$this->adapter->addForeignKey($table, $fk);
561+
$this->adapter->addForeignKey($table->getTable(), $fk);
537562
$this->assertTrue($this->adapter->hasForeignKey($table->getName(), ['ref_table_id'], 'fk1'));
538563
}
539564

@@ -649,7 +674,7 @@ public function testRemoveColumnComment()
649674

650675
$resultComment = $this->adapter->getColumnComment('table1', 'field1');
651676

652-
$this->assertEmpty($resultComment, 'Dont remove column comment correctly');
677+
$this->assertEmpty($resultComment, "Didn't remove column comment correctly: " . json_encode($resultComment));
653678
}
654679

655680
/**
@@ -676,7 +701,8 @@ public function testBulkInsertData()
676701
$table = new \Phinx\Db\Table('table1', [], $this->adapter);
677702
$table->addColumn('column1', 'string')
678703
->addColumn('column2', 'integer')
679-
->insert([
704+
->save();
705+
$table->insert([
680706
[
681707
'column1' => 'value1',
682708
'column2' => 1,
@@ -692,8 +718,7 @@ public function testBulkInsertData()
692718
'column2' => 3,
693719
]
694720
);
695-
$this->adapter->createTable($table);
696-
$this->adapter->bulkinsert($table, $table->getData());
721+
$this->adapter->bulkinsert($table->getTable(), $table->getData());
697722
$table->reset();
698723

699724
$rows = $this->adapter->fetchAll('SELECT * FROM table1');

0 commit comments

Comments
 (0)