Skip to content
This repository has been archived by the owner on Jan 16, 2019. It is now read-only.

Commit

Permalink
fix path
Browse files Browse the repository at this point in the history
  • Loading branch information
mikey179 committed Aug 15, 2014
1 parent 17c4bb8 commit 2c233b7
Showing 1 changed file with 45 additions and 76 deletions.
121 changes: 45 additions & 76 deletions src/test/php/ConsoleAppTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
* @package stubbles\console
*/
namespace stubbles\console;
use stubbles\lang\Rootpath;
use stubbles\streams\memory\MemoryOutputStream;
use org\stubbles\console\test\AppWithoutBindingCanGetConsoleClassesInjected;
use org\stubbles\console\test\ConsoleAppUsingBindingModule;
Expand Down Expand Up @@ -36,18 +37,27 @@ public function setUp()
TestConsoleApp::$exception = null;
}

/**
* @param string[] $argv
* @return ConsoleApp
*/
private function createStubCliApp(array $argv)
{
return ConsoleApp::stubcli(
new Rootpath(),
$argv,
$this->errorOutputStream
);
}

/**
* @test
*/
public function missingClassnameOptionLeadsToExistCode1()
{
$this->assertEquals(
1,
TestConsoleApp::stubcli(
'projectPath',
[],
$this->errorOutputStream
)
$this->createStubCliApp([])
);
}

Expand All @@ -56,7 +66,7 @@ public function missingClassnameOptionLeadsToExistCode1()
*/
public function missingClassnameOptionWritesErrorMessageToErrorStream()
{
TestConsoleApp::stubcli('projectPath', [], $this->errorOutputStream);
$this->createStubCliApp([]);
$this->assertEquals(
'*** Missing classname option -c',
trim($this->errorOutputStream->buffer())
Expand All @@ -70,11 +80,7 @@ public function missingClassnameValueInOptionLeadsToExistCode2()
{
$this->assertEquals(
2,
TestConsoleApp::stubcli(
'projectPath',
['-c'],
$this->errorOutputStream
)
$this->createStubCliApp(['-c'])
);
}

Expand All @@ -83,7 +89,7 @@ public function missingClassnameValueInOptionLeadsToExistCode2()
*/
public function missingClassnameValueInOptionWritesErrorMessageToErrorStream()
{
TestConsoleApp::stubcli('projectPath', ['-c'],$this->errorOutputStream);
$this->createStubCliApp(['-c']);
$this->assertEquals(
'*** No classname specified in -c',
trim($this->errorOutputStream->buffer())
Expand All @@ -97,11 +103,7 @@ public function invalidClassnameLeadsToExistCode3()
{
$this->assertEquals(
3,
TestConsoleApp::stubcli(
'projectPath',
['-c', 'doesNotExist'],
$this->errorOutputStream
)
$this->createStubCliApp(['-c', 'doesNotExist'])
);
}

Expand All @@ -110,7 +112,7 @@ public function invalidClassnameLeadsToExistCode3()
*/
public function invalidClassnameWritesErrorMessageToErrorStream()
{
TestConsoleApp::stubcli('projectPath',['-c', 'doesNotExist'], $this->errorOutputStream);
$this->createStubCliApp(['-c', 'doesNotExist']);
$this->assertEquals(
'*** Can not find doesNotExist',
trim($this->errorOutputStream->buffer())
Expand All @@ -125,13 +127,11 @@ public function thrownConsoleAppExceptionInStubCliLeadsToExitCodeOfException()
TestConsoleApp::$exception = new ConsoleAppException('failure', 10);
$this->assertEquals(
10,
ConsoleApp::stubcli(
'projectPath',
$this->createStubCliApp(
['stubcli',
'-c',
'org\stubbles\console\test\TestConsoleApp'
],
$this->errorOutputStream
]
)
);
}
Expand All @@ -142,13 +142,11 @@ public function thrownConsoleAppExceptionInStubCliLeadsToExitCodeOfException()
public function messageFromConsoleAppExceptionThrownInStubcliIsWrittenToErrorStream()
{
TestConsoleApp::$exception = new ConsoleAppException('failure', 10);
ConsoleApp::stubcli(
'projectPath',
$this->createStubCliApp(
['stubcli',
'-c',
'org\stubbles\console\test\TestConsoleApp'
],
$this->errorOutputStream
]
);
$this->assertEquals(
'*** Exception: failure',
Expand All @@ -167,13 +165,11 @@ public function thrownConsoleAppExceptionWithMessageClosureIsWrittenToErrorStrea
},
10
);
ConsoleApp::stubcli(
'projectPath',
$this->createStubCliApp(
['stubcli',
'-c',
'org\stubbles\console\test\TestConsoleApp'
],
$this->errorOutputStream
]
);
$this->assertEquals(
'something happened',
Expand All @@ -189,13 +185,11 @@ public function applicationExceptionThrownInStubCliLeadsToExitCode20()
TestConsoleApp::$exception = new \Exception('failure');
$this->assertEquals(
20,
ConsoleApp::stubcli(
'projectPath',
$this->createStubCliApp(
['stubcli',
'-c',
'org\stubbles\console\test\TestConsoleApp'
],
$this->errorOutputStream
]
)
);
}
Expand All @@ -207,13 +201,11 @@ public function messageFromApplicationExceptionThrownInStubCliIsWrittenToErrorSt
{
$e = new \Exception('failure');
TestConsoleApp::$exception = $e;
ConsoleApp::stubcli(
'projectPath',
$this->createStubCliApp(
['stubcli',
'-c',
'org\stubbles\console\test\TestConsoleApp'
],
$this->errorOutputStream
]
);
$this->assertEquals(
"*** Exception: failure\nStacktrace:\n" . $e->getTraceAsString(),
Expand All @@ -228,13 +220,11 @@ public function commandReturnCodeIsReturnedInStubcli()
{
$this->assertEquals(
0,
ConsoleApp::stubcli(
'projectPath',
$this->createStubCliApp(
['stubcli',
'-c',
'org\stubbles\console\test\TestConsoleApp'
],
$this->errorOutputStream
'-c',
'org\stubbles\console\test\TestConsoleApp'
]
)
);
}
Expand All @@ -246,16 +236,14 @@ public function detectsClassNameIfOnOtherPosition()
{
$this->assertEquals(
0,
ConsoleApp::stubcli(
'projectPath',
$this->createStubCliApp(
['stubcli',
'-v',
'-other',
'value',
'-c',
'org\stubbles\console\test\TestConsoleApp'
],
$this->errorOutputStream
]
)
);
}
Expand Down Expand Up @@ -283,10 +271,7 @@ public function messageFromConsoleAppExceptionThrownInMainIsWrittenToErrorStream
TestConsoleApp::$exception = new ConsoleAppException('failure', 10);
$this->assertEquals(
10,
TestConsoleApp::main(
'projectPath',
$this->errorOutputStream
)
TestConsoleApp::main(new Rootpath(), $this->errorOutputStream)
);
$this->assertEquals(
'*** Exception: failure',
Expand All @@ -305,10 +290,7 @@ public function messageClosureFromConsoleAppExceptionThrownInMainIsWrittenToErro
},
10
);
TestConsoleApp::main(
'projectPath',
$this->errorOutputStream
);
TestConsoleApp::main(new Rootpath(), $this->errorOutputStream);
$this->assertEquals(
'something happened',
trim($this->errorOutputStream->buffer())
Expand All @@ -323,10 +305,7 @@ public function applicationExceptionThrownInMainLeadsToExitCode20()
TestConsoleApp::$exception = new \Exception('failure');
$this->assertEquals(
20,
TestConsoleApp::main(
'projectPath',
$this->errorOutputStream
)
TestConsoleApp::main(new Rootpath(), $this->errorOutputStream)
);
}

Expand All @@ -337,10 +316,7 @@ public function messageFromApplicationExceptionThrownInMainIsWrittenToErrorStrea
{
$e = new \Exception('failure');
TestConsoleApp::$exception = $e;
TestConsoleApp::main(
'projectPath',
$this->errorOutputStream
);
TestConsoleApp::main(new Rootpath(), $this->errorOutputStream);
$this->assertEquals(
"*** Exception: failure\nStacktrace:\n" . $e->getTraceAsString(),
trim($this->errorOutputStream->buffer())
Expand All @@ -354,10 +330,7 @@ public function commandReturnCodeIsReturned()
{
$this->assertEquals(
0,
TestConsoleApp::main(
'projectPath',
$this->errorOutputStream
)
TestConsoleApp::main(new Rootpath(), $this->errorOutputStream)
);
}

Expand Down Expand Up @@ -408,14 +381,12 @@ public function canCreateInstanceWithSelfBoundApp()
$_SERVER['argv'][1] = 'value';
$this->assertEquals(
0,
ConsoleApp::stubcli(
'projectPath',
$this->createStubCliApp(
['stubcli',
'value',
'-c',
'org\stubbles\console\test\SelfBoundConsoleApp'
],
$this->errorOutputStream
]
)
);
$this->assertEquals('value', SelfBoundConsoleApp::$bar);
Expand All @@ -428,14 +399,12 @@ public function canCreateInstanceWithSelfBoundApp()
public function successfulInstanceCreationDoesNotWriteToErrorStream()
{
$_SERVER['argv'][1] = 'value';
ConsoleApp::stubcli(
'projectPath',
$this->createStubCliApp(
['stubcli',
'value',
'-c',
'org\stubbles\console\test\SelfBoundConsoleApp'
],
$this->errorOutputStream
]
);
$this->assertEquals('', $this->errorOutputStream->buffer());
}
Expand Down

0 comments on commit 2c233b7

Please sign in to comment.