diff options
author | Joas Schilling <coding@schilljs.com> | 2017-06-09 16:45:12 +0200 |
---|---|---|
committer | Morris Jobke <hey@morrisjobke.de> | 2017-07-05 13:02:16 +0200 |
commit | 4e5cd1efea7c522ebd763dd3b96eb5f8c0e8407b (patch) | |
tree | a184e5b30726048e278f504ebfaa08986a716235 /tests/lib | |
parent | 7a3d83d63038e5db0af790b827b73ec7335a6961 (diff) | |
download | nextcloud-server-4e5cd1efea7c522ebd763dd3b96eb5f8c0e8407b.tar.gz nextcloud-server-4e5cd1efea7c522ebd763dd3b96eb5f8c0e8407b.zip |
Fix tests of CodeChecker and MigrationService
Signed-off-by: Joas Schilling <coding@schilljs.com>
Diffstat (limited to 'tests/lib')
-rw-r--r-- | tests/lib/App/CodeChecker/CodeCheckerTest.php | 6 | ||||
-rw-r--r-- | tests/lib/App/CodeChecker/DeprecationCheckTest.php | 6 | ||||
-rw-r--r-- | tests/lib/App/CodeChecker/NodeVisitorTest.php | 3 | ||||
-rw-r--r-- | tests/lib/App/CodeChecker/StrongComparisonCheckTest.php | 6 | ||||
-rw-r--r-- | tests/lib/DB/MigrationsTest.php | 90 |
5 files changed, 83 insertions, 28 deletions
diff --git a/tests/lib/App/CodeChecker/CodeCheckerTest.php b/tests/lib/App/CodeChecker/CodeCheckerTest.php index cdbb7c17da5..bb121eccc44 100644 --- a/tests/lib/App/CodeChecker/CodeCheckerTest.php +++ b/tests/lib/App/CodeChecker/CodeCheckerTest.php @@ -23,7 +23,8 @@ class CodeCheckerTest extends TestCase { */ public function testFindInvalidUsage($expectedErrorToken, $expectedErrorCode, $fileToVerify) { $checker = new CodeChecker( - new PrivateCheck(new EmptyCheck()) + new PrivateCheck(new EmptyCheck()), + false ); $errors = $checker->analyseFile(\OC::$SERVERROOT . "/tests/data/app/code-checker/$fileToVerify"); @@ -49,7 +50,8 @@ class CodeCheckerTest extends TestCase { */ public function testPassValidUsage($fileToVerify) { $checker = new CodeChecker( - new PrivateCheck(new EmptyCheck()) + new PrivateCheck(new EmptyCheck()), + false ); $errors = $checker->analyseFile(\OC::$SERVERROOT . "/tests/data/app/code-checker/$fileToVerify"); diff --git a/tests/lib/App/CodeChecker/DeprecationCheckTest.php b/tests/lib/App/CodeChecker/DeprecationCheckTest.php index ee69f075a61..1a16e7e4920 100644 --- a/tests/lib/App/CodeChecker/DeprecationCheckTest.php +++ b/tests/lib/App/CodeChecker/DeprecationCheckTest.php @@ -23,7 +23,8 @@ class DeprecationCheckTest extends TestCase { */ public function testFindInvalidUsage($expectedErrorToken, $expectedErrorCode, $fileToVerify) { $checker = new CodeChecker( - new DeprecationCheck(new EmptyCheck()) + new DeprecationCheck(new EmptyCheck()), + false ); $errors = $checker->analyseFile(\OC::$SERVERROOT . "/tests/data/app/code-checker/$fileToVerify"); @@ -48,7 +49,8 @@ class DeprecationCheckTest extends TestCase { */ public function testPassValidUsage($fileToVerify) { $checker = new CodeChecker( - new DeprecationCheck(new EmptyCheck()) + new DeprecationCheck(new EmptyCheck()), + false ); $errors = $checker->analyseFile(\OC::$SERVERROOT . "/tests/data/app/code-checker/$fileToVerify"); diff --git a/tests/lib/App/CodeChecker/NodeVisitorTest.php b/tests/lib/App/CodeChecker/NodeVisitorTest.php index ca0b6e9ccc1..d1b1f643677 100644 --- a/tests/lib/App/CodeChecker/NodeVisitorTest.php +++ b/tests/lib/App/CodeChecker/NodeVisitorTest.php @@ -59,7 +59,8 @@ class NodeVisitorTest extends TestCase { */ public function testMethodsToCheck($expectedErrors, $fileToVerify) { $checker = new CodeChecker( - new TestList(new EmptyCheck()) + new TestList(new EmptyCheck()), + false ); $errors = $checker->analyseFile(\OC::$SERVERROOT . "/tests/data/app/code-checker/$fileToVerify"); diff --git a/tests/lib/App/CodeChecker/StrongComparisonCheckTest.php b/tests/lib/App/CodeChecker/StrongComparisonCheckTest.php index c73eae286ab..6d3d2f50efd 100644 --- a/tests/lib/App/CodeChecker/StrongComparisonCheckTest.php +++ b/tests/lib/App/CodeChecker/StrongComparisonCheckTest.php @@ -23,7 +23,8 @@ class StrongComparisonCheckTest extends TestCase { */ public function testFindInvalidUsage($expectedErrorToken, $expectedErrorCode, $fileToVerify) { $checker = new CodeChecker( - new StrongComparisonCheck(new EmptyCheck()) + new StrongComparisonCheck(new EmptyCheck()), + false ); $errors = $checker->analyseFile(\OC::$SERVERROOT . "/tests/data/app/code-checker/$fileToVerify"); @@ -45,7 +46,8 @@ class StrongComparisonCheckTest extends TestCase { */ public function testPassValidUsage($fileToVerify) { $checker = new CodeChecker( - new StrongComparisonCheck(new EmptyCheck()) + new StrongComparisonCheck(new EmptyCheck()), + false ); $errors = $checker->analyseFile(\OC::$SERVERROOT . "/tests/data/app/code-checker/$fileToVerify"); diff --git a/tests/lib/DB/MigrationsTest.php b/tests/lib/DB/MigrationsTest.php index fbb54bf9a1b..a255cd1b596 100644 --- a/tests/lib/DB/MigrationsTest.php +++ b/tests/lib/DB/MigrationsTest.php @@ -13,7 +13,9 @@ namespace Test\DB; use Doctrine\DBAL\Schema\Schema; use OC\DB\Connection; use OC\DB\MigrationService; +use OC\DB\SchemaWrapper; use OCP\IDBConnection; +use OCP\Migration\IMigrationStep; use OCP\Migration\ISchemaMigration; use OCP\Migration\ISqlMigration; @@ -39,8 +41,8 @@ class MigrationsTest extends \Test\TestCase { public function testGetters() { $this->assertEquals('testing', $this->migrationService->getApp()); - $this->assertEquals(\OC::$SERVERROOT . '/apps/testing/appinfo/Migrations', $this->migrationService->getMigrationsDirectory()); - $this->assertEquals('OCA\testing\Migrations', $this->migrationService->getMigrationsNamespace()); + $this->assertEquals(\OC::$SERVERROOT . '/apps/testing/lib/Migration', $this->migrationService->getMigrationsDirectory()); + $this->assertEquals('OCA\Testing\Migration', $this->migrationService->getMigrationsNamespace()); $this->assertEquals('test_oc_migrations', $this->migrationService->getMigrationsTableName()); } @@ -84,36 +86,88 @@ class MigrationsTest extends \Test\TestCase { $this->migrationService->executeStep('20170130180000'); } - public function testExecuteStepWithSchemaMigrationStep() { + public function testExecuteStepWithSchemaChange() { $schema = $this->createMock(Schema::class); - $this->db->expects($this->any())->method('createSchema')->willReturn($schema); + $this->db->expects($this->any()) + ->method('createSchema') + ->willReturn($schema); + + $this->db->expects($this->once()) + ->method('migrateToSchema'); + + $schemaResult = $this->createMock(SchemaWrapper::class); + $schemaResult->expects($this->once()) + ->method('getWrappedSchema') + ->willReturn($this->createMock(Schema::class)); + + $step = $this->createMock(IMigrationStep::class); + $step->expects($this->at(0)) + ->method('preSchemaChange'); + $step->expects($this->at(1)) + ->method('changeSchema') + ->willReturn($schemaResult); + $step->expects($this->at(2)) + ->method('postSchemaChange'); - $step = $this->createMock(ISchemaMigration::class); - $step->expects($this->once())->method('changeSchema'); $this->migrationService = $this->getMockBuilder(MigrationService::class) ->setMethods(['createInstance']) ->setConstructorArgs(['testing', $this->db]) ->getMock(); - $this->migrationService->expects($this->any())->method('createInstance')->with('20170130180000')->willReturn($step); + + $this->migrationService->expects($this->any()) + ->method('createInstance') + ->with('20170130180000') + ->willReturn($step); $this->migrationService->executeStep('20170130180000'); } - public function testExecuteStepWithSqlMigrationStep() { + public function testExecuteStepWithoutSchemaChange() { - $this->db->expects($this->exactly(3))->method('executeQuery')->withConsecutive(['1'], ['2'], ['3']); + $schema = $this->createMock(Schema::class); + $this->db->expects($this->any()) + ->method('createSchema') + ->willReturn($schema); + + $this->db->expects($this->never()) + ->method('migrateToSchema'); + + $step = $this->createMock(IMigrationStep::class); + $step->expects($this->at(0)) + ->method('preSchemaChange'); + $step->expects($this->at(1)) + ->method('changeSchema') + ->willReturn(null); + $step->expects($this->at(2)) + ->method('postSchemaChange'); - $step = $this->createMock(ISqlMigration::class); - $step->expects($this->once())->method('sql')->willReturn(['1', '2', '3']); $this->migrationService = $this->getMockBuilder(MigrationService::class) ->setMethods(['createInstance']) ->setConstructorArgs(['testing', $this->db]) ->getMock(); - $this->migrationService->expects($this->any())->method('createInstance')->with('20170130180000')->willReturn($step); + + $this->migrationService->expects($this->any()) + ->method('createInstance') + ->with('20170130180000') + ->willReturn($step); $this->migrationService->executeStep('20170130180000'); } - public function testGetMigration() { + public function dataGetMigration() { + return [ + ['current', '20170130180001'], + ['prev', '20170130180000'], + ['next', '20170130180002'], + ['latest', '20170130180003'], + ]; + } + + /** + * @dataProvider dataGetMigration + * @param string $alias + * @param string $expected + */ + public function testGetMigration($alias, $expected) { $this->migrationService = $this->getMockBuilder(MigrationService::class) ->setMethods(['getMigratedVersions', 'findMigrations']) ->setConstructorArgs(['testing', $this->db]) @@ -129,14 +183,8 @@ class MigrationsTest extends \Test\TestCase { ['20170130180000', '20170130180001', '20170130180002', '20170130180003'], $this->migrationService->getAvailableVersions()); - $migration = $this->migrationService->getMigration('current'); - $this->assertEquals('20170130180001', $migration); - $migration = $this->migrationService->getMigration('prev'); - $this->assertEquals('20170130180000', $migration); - $migration = $this->migrationService->getMigration('next'); - $this->assertEquals('20170130180002', $migration); - $migration = $this->migrationService->getMigration('latest'); - $this->assertEquals('20170130180003', $migration); + $migration = $this->migrationService->getMigration($alias); + $this->assertEquals($expected, $migration); } public function testMigrate() { |