Browse Source

Fix tests of CodeChecker and MigrationService

Signed-off-by: Joas Schilling <coding@schilljs.com>
tags/v13.0.0beta1
Joas Schilling 7 years ago
parent
commit
4e5cd1efea

+ 1
- 1
lib/private/DB/MigrationService.php View File

*/ */
public function getAvailableVersions() { public function getAvailableVersions() {
$this->ensureMigrationsAreLoaded(); $this->ensureMigrationsAreLoaded();
return array_keys($this->migrations);
return array_map('strval', array_keys($this->migrations));
} }


protected function findMigrations() { protected function findMigrations() {

+ 4
- 2
tests/lib/App/CodeChecker/CodeCheckerTest.php View File

*/ */
public function testFindInvalidUsage($expectedErrorToken, $expectedErrorCode, $fileToVerify) { public function testFindInvalidUsage($expectedErrorToken, $expectedErrorCode, $fileToVerify) {
$checker = new CodeChecker( $checker = new CodeChecker(
new PrivateCheck(new EmptyCheck())
new PrivateCheck(new EmptyCheck()),
false
); );
$errors = $checker->analyseFile(\OC::$SERVERROOT . "/tests/data/app/code-checker/$fileToVerify"); $errors = $checker->analyseFile(\OC::$SERVERROOT . "/tests/data/app/code-checker/$fileToVerify");


*/ */
public function testPassValidUsage($fileToVerify) { public function testPassValidUsage($fileToVerify) {
$checker = new CodeChecker( $checker = new CodeChecker(
new PrivateCheck(new EmptyCheck())
new PrivateCheck(new EmptyCheck()),
false
); );
$errors = $checker->analyseFile(\OC::$SERVERROOT . "/tests/data/app/code-checker/$fileToVerify"); $errors = $checker->analyseFile(\OC::$SERVERROOT . "/tests/data/app/code-checker/$fileToVerify");



+ 4
- 2
tests/lib/App/CodeChecker/DeprecationCheckTest.php View File

*/ */
public function testFindInvalidUsage($expectedErrorToken, $expectedErrorCode, $fileToVerify) { public function testFindInvalidUsage($expectedErrorToken, $expectedErrorCode, $fileToVerify) {
$checker = new CodeChecker( $checker = new CodeChecker(
new DeprecationCheck(new EmptyCheck())
new DeprecationCheck(new EmptyCheck()),
false
); );
$errors = $checker->analyseFile(\OC::$SERVERROOT . "/tests/data/app/code-checker/$fileToVerify"); $errors = $checker->analyseFile(\OC::$SERVERROOT . "/tests/data/app/code-checker/$fileToVerify");


*/ */
public function testPassValidUsage($fileToVerify) { public function testPassValidUsage($fileToVerify) {
$checker = new CodeChecker( $checker = new CodeChecker(
new DeprecationCheck(new EmptyCheck())
new DeprecationCheck(new EmptyCheck()),
false
); );
$errors = $checker->analyseFile(\OC::$SERVERROOT . "/tests/data/app/code-checker/$fileToVerify"); $errors = $checker->analyseFile(\OC::$SERVERROOT . "/tests/data/app/code-checker/$fileToVerify");



+ 2
- 1
tests/lib/App/CodeChecker/NodeVisitorTest.php View File

*/ */
public function testMethodsToCheck($expectedErrors, $fileToVerify) { public function testMethodsToCheck($expectedErrors, $fileToVerify) {
$checker = new CodeChecker( $checker = new CodeChecker(
new TestList(new EmptyCheck())
new TestList(new EmptyCheck()),
false
); );
$errors = $checker->analyseFile(\OC::$SERVERROOT . "/tests/data/app/code-checker/$fileToVerify"); $errors = $checker->analyseFile(\OC::$SERVERROOT . "/tests/data/app/code-checker/$fileToVerify");



+ 4
- 2
tests/lib/App/CodeChecker/StrongComparisonCheckTest.php View File

*/ */
public function testFindInvalidUsage($expectedErrorToken, $expectedErrorCode, $fileToVerify) { public function testFindInvalidUsage($expectedErrorToken, $expectedErrorCode, $fileToVerify) {
$checker = new CodeChecker( $checker = new CodeChecker(
new StrongComparisonCheck(new EmptyCheck())
new StrongComparisonCheck(new EmptyCheck()),
false
); );
$errors = $checker->analyseFile(\OC::$SERVERROOT . "/tests/data/app/code-checker/$fileToVerify"); $errors = $checker->analyseFile(\OC::$SERVERROOT . "/tests/data/app/code-checker/$fileToVerify");


*/ */
public function testPassValidUsage($fileToVerify) { public function testPassValidUsage($fileToVerify) {
$checker = new CodeChecker( $checker = new CodeChecker(
new StrongComparisonCheck(new EmptyCheck())
new StrongComparisonCheck(new EmptyCheck()),
false
); );
$errors = $checker->analyseFile(\OC::$SERVERROOT . "/tests/data/app/code-checker/$fileToVerify"); $errors = $checker->analyseFile(\OC::$SERVERROOT . "/tests/data/app/code-checker/$fileToVerify");



+ 69
- 21
tests/lib/DB/MigrationsTest.php View File

use Doctrine\DBAL\Schema\Schema; use Doctrine\DBAL\Schema\Schema;
use OC\DB\Connection; use OC\DB\Connection;
use OC\DB\MigrationService; use OC\DB\MigrationService;
use OC\DB\SchemaWrapper;
use OCP\IDBConnection; use OCP\IDBConnection;
use OCP\Migration\IMigrationStep;
use OCP\Migration\ISchemaMigration; use OCP\Migration\ISchemaMigration;
use OCP\Migration\ISqlMigration; use OCP\Migration\ISqlMigration;




public function testGetters() { public function testGetters() {
$this->assertEquals('testing', $this->migrationService->getApp()); $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()); $this->assertEquals('test_oc_migrations', $this->migrationService->getMigrationsTableName());
} }


$this->migrationService->executeStep('20170130180000'); $this->migrationService->executeStep('20170130180000');
} }


public function testExecuteStepWithSchemaMigrationStep() {
public function testExecuteStepWithSchemaChange() {


$schema = $this->createMock(Schema::class); $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) $this->migrationService = $this->getMockBuilder(MigrationService::class)
->setMethods(['createInstance']) ->setMethods(['createInstance'])
->setConstructorArgs(['testing', $this->db]) ->setConstructorArgs(['testing', $this->db])
->getMock(); ->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'); $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) $this->migrationService = $this->getMockBuilder(MigrationService::class)
->setMethods(['createInstance']) ->setMethods(['createInstance'])
->setConstructorArgs(['testing', $this->db]) ->setConstructorArgs(['testing', $this->db])
->getMock(); ->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'); $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) $this->migrationService = $this->getMockBuilder(MigrationService::class)
->setMethods(['getMigratedVersions', 'findMigrations']) ->setMethods(['getMigratedVersions', 'findMigrations'])
->setConstructorArgs(['testing', $this->db]) ->setConstructorArgs(['testing', $this->db])
['20170130180000', '20170130180001', '20170130180002', '20170130180003'], ['20170130180000', '20170130180001', '20170130180002', '20170130180003'],
$this->migrationService->getAvailableVersions()); $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() { public function testMigrate() {

Loading…
Cancel
Save