Skip to content

Commit

Permalink
Merge branch 'ftwbzhao-feature/command'
Browse files Browse the repository at this point in the history
  • Loading branch information
kenjis committed May 21, 2015
2 parents 805bedc + 7c15d2c commit 1c46461
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 25 deletions.
6 changes: 3 additions & 3 deletions tests/Command/GenerateTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public function test_no_generator()
$this->assertEquals(Status::FAILURE, $status);

$this->stderr->rewind();
$actual = $this->stderr->fread(8192);
$actual = $this->stderr->fread();
$expected = 'No such generator class: Kenjis\CodeIgniter_Cli\Command\Generate\Not_exists' . PHP_EOL;
$this->assertEquals($expected, $actual);
}
Expand All @@ -39,7 +39,7 @@ public function test_migration_no_classname()
$this->assertEquals(Status::USAGE, $status);

$this->stderr->rewind();
$actual = $this->stderr->fread(8192);
$actual = $this->stderr->fread();
$expected = 'Classname is needed' . PHP_EOL
. ' eg, generate migration CreateUserTable' . PHP_EOL;
$this->assertEquals($expected, $actual);
Expand Down Expand Up @@ -80,7 +80,7 @@ public function test_migration_cannot_write_to_file()
$this->assertEquals(Status::FAILURE, $status);

$this->stderr->rewind();
$actual = $this->stderr->fread(8192);
$actual = $this->stderr->fread();
$this->assertContains("Can't write to ", $actual);
$this->assertContains('Fake/migrations/not-exist-dir/', $actual);
$this->assertContains('Test_of_generate_migration.php', $actual);
Expand Down
18 changes: 9 additions & 9 deletions tests/Command/MigrateTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,15 @@ public function test_command_not_exists()
$this->assertEquals(Status::USAGE, $status);

$this->stderr->rewind();
$actual = $this->stderr->fread(8192);
$actual = $this->stderr->fread();
$expected = 'No such command: command-not-exists' . PHP_EOL;
$this->assertEquals($expected, $actual);
}

public function test_migrate()
{
$status = $this->cmd->__invoke();
$this->assertEquals(0, $status);
$this->assertEquals(Status::SUCCESS, $status);
}

public function test_migrate_to_version_not_exists()
Expand All @@ -58,16 +58,16 @@ public function test_migrate_to_version_not_exists()
public function test_migrate_to_specific_version()
{
$status = $this->cmd->__invoke('20150429110003');
$this->assertEquals(0, $status);
$this->assertEquals(Status::SUCCESS, $status);
}

public function test_status()
{
$status = $this->cmd->__invoke('status');
$this->assertEquals(0, $status);
$this->assertEquals(Status::SUCCESS, $status);

$this->stdout->rewind();
$actual = $this->stdout->fread(8192);
$actual = $this->stdout->fread();
$this->assertContains('20150429090001_Create_bbs.php', $actual);
$this->assertContains('20150429110003_Create_category.php (current/database)', $actual);
}
Expand All @@ -76,21 +76,21 @@ public function test_status_current_not_equals_database()
{
$this->ci->config->set_item('migration_version', 20150429120004);
$status = $this->cmd->__invoke('status');
$this->assertEquals(0, $status);
$this->assertEquals(Status::SUCCESS, $status);

$this->stdout->rewind();
$actual = $this->stdout->fread(8192);
$actual = $this->stdout->fread();
$this->assertContains('20150429110003_Create_category.php (database)', $actual);
$this->assertContains('20150429120004_Create_product.php (current)', $actual);
}

public function test_version()
{
$status = $this->cmd->__invoke('version');
$this->assertEquals(0, $status);
$this->assertEquals(Status::SUCCESS, $status);

$this->stdout->rewind();
$actual = $this->stdout->fread(8192);
$actual = $this->stdout->fread();
$this->assertContains(' current: 20150429110003 (in config/migration.php)', $actual);
$this->assertContains('database: 20150429110003 (in database table)', $actual);
$this->assertContains(' latest: 20150429120004 (in migration files)', $actual);
Expand Down
6 changes: 3 additions & 3 deletions tests/Command/RunTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public function test_run_no_controller()
$this->assertEquals(Status::USAGE, $status);

$this->stderr->rewind();
$actual = $this->stderr->fread(8192);
$actual = $this->stderr->fread();
$expected = 'Controller is needed' . PHP_EOL;
$this->assertEquals($expected, $actual);
}
Expand All @@ -38,10 +38,10 @@ public function test_run_welcome()
ob_start();
$status = $this->cmd->__invoke('welcome');
ob_end_clean();
$this->assertEquals(0, $status);
$this->assertEquals(Status::SUCCESS, $status);

$this->stdout->rewind();
$actual = $this->stdout->fread(8192);
$actual = $this->stdout->fread();
$expected = 'php public/index.php welcome';
$this->assertContains($expected, $actual);
}
Expand Down
12 changes: 6 additions & 6 deletions tests/Command/SeedTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ public function test_seed()
{
$this->expectOutputString('Table1SeederTable2SeederTable1Seeder');
$status = $this->cmd->__invoke();
$this->assertEquals(0, $status);
$this->assertEquals(Status::SUCCESS, $status);

$this->stdout->rewind();
$actual = $this->stdout->fread(8192);
$actual = $this->stdout->fread();
$expected = 'Seeded: Table1Seeder' . PHP_EOL
. 'Seeded: Table2Seeder' . PHP_EOL
. 'Seeded: Table1Seeder' . PHP_EOL
Expand All @@ -44,10 +44,10 @@ public function test_seed_specific_class()
{
$this->expectOutputString('Table1Seeder');
$status = $this->cmd->__invoke('Table1Seeder');
$this->assertEquals(0, $status);
$this->assertEquals(Status::SUCCESS, $status);

$this->stdout->rewind();
$actual = $this->stdout->fread(8192);
$actual = $this->stdout->fread();
$expected = 'Seeded: Table1Seeder' . PHP_EOL;
$this->assertEquals($expected, $actual);
}
Expand All @@ -65,10 +65,10 @@ public function test_seed_list()
$this->cmd->setSeederPath($this->seeder_path);

$status = $this->cmd->__invoke();
$this->assertEquals(0, $status);
$this->assertEquals(Status::SUCCESS, $status);

$this->stdout->rewind();
$actual = $this->stdout->fread(8192);
$actual = $this->stdout->fread();
$this->assertContains('Table1Seeder', $actual);
$this->assertContains('Table2Seeder', $actual);
}
Expand Down
8 changes: 4 additions & 4 deletions tests/UserConfigTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public function test_registerCommandClasses()
$ci = new \stdClass();
$paths = [ __DIR__ . '/Fake/user_commands/' ];
UserConfig::registerCommandClasses($this->di, $ci, $paths);

$this->assertTrue(array_key_exists('TestCommand', $this->di->params));
}

Expand All @@ -42,10 +42,10 @@ public function test_registerCommandClasses_bad_classname()
$ci = new \stdClass();
$paths = [ __DIR__ . '/Fake/user_commands_bad/' ];
UserConfig::registerCommandClasses($this->di, $ci, $paths);

$stderr = $this->di->get('aura/cli-kernel:stdio')->getStderr();
$stderr->rewind();
$actual = $stderr->fread(8192);
$actual = $stderr->fread();
$expected = 'No such class: BadCommand';
$this->assertContains($expected, $actual);
}
Expand All @@ -66,7 +66,7 @@ public function test_registerCommands()
$help_service = $this->di->get('aura/cli-kernel:help_service');
$paths = [ __DIR__ . '/Fake/user_commands/' ];
UserConfig::registerCommands($this->di, $dispatcher, $help_service, $paths);

$this->assertTrue($dispatcher->hasObject('test'));
$this->assertTrue($help_service->has('test'));
}
Expand Down

0 comments on commit 1c46461

Please sign in to comment.