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

Commit

Permalink
use ::class syntax instead of floating around strings
Browse files Browse the repository at this point in the history
  • Loading branch information
mikey179 committed Dec 10, 2015
1 parent 9c2abff commit ef45262
Show file tree
Hide file tree
Showing 14 changed files with 99 additions and 74 deletions.
11 changes: 6 additions & 5 deletions src/main/php/ConsoleApp.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use stubbles\console\ioc\ArgumentParser;
use stubbles\ioc\App;
use stubbles\ioc\Binder;
use stubbles\streams\InputStream;
use stubbles\streams\OutputStream;
/**
* Base class for console applications.
Expand Down Expand Up @@ -128,17 +129,17 @@ protected static function getBindingsForApp($className)
$bindings = parent::getBindingsForApp($className);
$bindings[] = function(Binder $binder)
{
$binder->bind('stubbles\streams\InputStream')
$binder->bind(InputStream::class)
->named('stdin')
->toInstance(ConsoleInputStream::forIn());
$binder->bind('stubbles\streams\OutputStream')
$binder->bind(OutputStream::class)
->named('stdout')
->toInstance(ConsoleOutputStream::forOut());
$binder->bind('stubbles\streams\OutputStream')
$binder->bind(OutputStream::class)
->named('stderr')
->toInstance(ConsoleOutputStream::forError());
$binder->bind('stubbles\console\Executor')
->to('stubbles\console\ConsoleExecutor');
$binder->bind(Executor::class)
->to(ConsoleExecutor::class);
};
return $bindings;
}
Expand Down
9 changes: 6 additions & 3 deletions src/main/php/ioc/ArgumentParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@
* @package stubbles\console
*/
namespace stubbles\console\ioc;
use stubbles\console\input\UserInputProvider;
use stubbles\input\Request;
use stubbles\input\broker\RequestBroker;
use stubbles\input\console\ConsoleRequest;
use stubbles\input\console\BaseConsoleRequest;
use stubbles\ioc\Binder;
use stubbles\ioc\module\BindingModule;
Expand Down Expand Up @@ -118,13 +121,13 @@ public function configure(Binder $binder)
}

$request = new BaseConsoleRequest($args, $_SERVER);
$binder->bind('stubbles\input\Request')
$binder->bind(Request::class)
->toInstance($request);
$binder->bind('stubbles\input\console\ConsoleRequest')
$binder->bind(ConsoleRequest::class)
->toInstance($request);
if (null !== $this->userInput) {
$binder->bind($this->userInput)
->toProviderClass('stubbles\console\input\UserInputProvider')
->toProviderClass(UserInputProvider::class)
->asSingleton();
$binder->bind($this->userInput)
->named('stubbles.console.input.instance')
Expand Down
23 changes: 12 additions & 11 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\console\ioc\ArgumentParser;
use stubbles\lang\Rootpath;
use stubbles\streams\memory\MemoryOutputStream;
use org\stubbles\console\test\AppWithoutBindingCanGetConsoleClassesInjected;
Expand Down Expand Up @@ -139,7 +140,7 @@ public function thrownConsoleAppExceptionInStubCliLeadsToExitCodeOfException()
$this->createStubCliApp(
['stubcli',
'-c',
'org\stubbles\console\test\TestConsoleApp'
TestConsoleApp::class
]
)
);
Expand All @@ -154,7 +155,7 @@ public function messageFromConsoleAppExceptionThrownInStubcliIsWrittenToErrorStr
$this->createStubCliApp(
['stubcli',
'-c',
'org\stubbles\console\test\TestConsoleApp'
TestConsoleApp::class
]
);
assertEquals(
Expand All @@ -177,7 +178,7 @@ public function thrownConsoleAppExceptionWithMessageClosureIsWrittenToErrorStrea
$this->createStubCliApp(
['stubcli',
'-c',
'org\stubbles\console\test\TestConsoleApp'
TestConsoleApp::class
]
);
assertEquals(
Expand All @@ -197,7 +198,7 @@ public function applicationExceptionThrownInStubCliLeadsToExitCode20()
$this->createStubCliApp(
['stubcli',
'-c',
'org\stubbles\console\test\TestConsoleApp'
TestConsoleApp::class
]
)
);
Expand All @@ -213,7 +214,7 @@ public function messageFromApplicationExceptionThrownInStubCliIsWrittenToErrorSt
$this->createStubCliApp(
['stubcli',
'-c',
'org\stubbles\console\test\TestConsoleApp'
TestConsoleApp::class
]
);
assertEquals(
Expand All @@ -232,7 +233,7 @@ public function commandReturnCodeIsReturnedInStubcli()
$this->createStubCliApp(
['stubcli',
'-c',
'org\stubbles\console\test\TestConsoleApp'
TestConsoleApp::class
]
)
);
Expand All @@ -251,7 +252,7 @@ public function detectsClassNameIfOnOtherPosition()
'-other',
'value',
'-c',
'org\stubbles\console\test\TestConsoleApp'
TestConsoleApp::class
]
)
);
Expand Down Expand Up @@ -350,7 +351,7 @@ public function commandReturnCodeIsReturned()
public function parseArgumentsReturnsBindingModuleForArguments()
{
assertInstanceOf(
'stubbles\console\ioc\ArgumentParser',
ArgumentParser::class,
ConsoleAppUsingBindingModule::returnArgumentParser()
);
}
Expand All @@ -368,7 +369,7 @@ public function canCreateInstanceWithSelfBoundApp()
['stubcli',
'value',
'-c',
'org\stubbles\console\test\SelfBoundConsoleApp'
SelfBoundConsoleApp::class
]
)
);
Expand All @@ -386,7 +387,7 @@ public function successfulInstanceCreationDoesNotWriteToErrorStream()
['stubcli',
'value',
'-c',
'org\stubbles\console\test\SelfBoundConsoleApp'
SelfBoundConsoleApp::class
]
);
assertEquals('', $this->errorOutputStream->buffer());
Expand Down Expand Up @@ -439,7 +440,7 @@ public function executorIsBoundAutomatically()
{
$app = AppWithoutBindingCanGetConsoleClassesInjected::create('projectPath');
assertInstanceOf(
'stubbles\console\ConsoleExecutor',
ConsoleExecutor::class,
$app->executor
);
}
Expand Down
9 changes: 5 additions & 4 deletions src/test/php/ConsoleExecutorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
*/
namespace stubbles\console;
use bovigo\callmap\NewInstance;
use stubbles\streams\OutputStream;
use stubbles\streams\memory\MemoryOutputStream;
/**
* Test for stubbles\console\ConsoleExecutor.
Expand Down Expand Up @@ -61,7 +62,7 @@ public function executeWithoutOutputStream()
*/
public function outReturnsOutputStreamOriginallySet()
{
$outputStream = NewInstance::of('stubbles\streams\OutputStream');
$outputStream = NewInstance::of(OutputStream::class);
assertSame(
$outputStream,
$this->executor->streamOutputTo($outputStream)->out()
Expand Down Expand Up @@ -93,7 +94,7 @@ public function executeFailsThrowsRuntimeException()
public function executeAsyncReturnsStreamToReadResultFrom()
{
$commandInputStream = $this->executor->executeAsync('echo foo');
assertInstanceOf('stubbles\console\CommandInputStream', $commandInputStream);
assertInstanceOf(CommandInputStream::class, $commandInputStream);
assertEquals('foo', chop($commandInputStream->read()));
}

Expand All @@ -104,7 +105,7 @@ public function executeAsyncReturnsStreamToReadResultFrom()
public function executeAsyncFailsThrowsRuntimeException()
{
$commandInputStream = $this->executor->executeAsync('php -r "throw new Exception();"');
assertInstanceOf('stubbles\console\CommandInputStream', $commandInputStream);
assertInstanceOf(CommandInputStream::class, $commandInputStream);
while (!$commandInputStream->eof()) {
$commandInputStream->readLine();
}
Expand All @@ -128,7 +129,7 @@ public function illegalResourceForCommandInputStreamThrowsIllegalArgumentExcepti
public function readAfterCloseThrowsIllegalStateException()
{
$commandInputStream = $this->executor->executeAsync('echo foo');
assertInstanceOf('stubbles\console\CommandInputStream', $commandInputStream);
assertInstanceOf(CommandInputStream::class, $commandInputStream);
assertEquals('foo', chop($commandInputStream->read()));
$commandInputStream->close();
$commandInputStream->read();
Expand Down
3 changes: 2 additions & 1 deletion src/test/php/ConsoleInputStreamTest.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\streams\InputStream;
/**
* Test for stubbles\console\ConsoleInputStream.
*
Expand All @@ -21,7 +22,7 @@ class ConsoleInputStreamTest extends \PHPUnit_Framework_TestCase
public function returnsInstanceOfInputStream()
{
assertInstanceOf(
'stubbles\streams\InputStream',
InputStream::class,
ConsoleInputStream::forIn()
);
}
Expand Down
5 changes: 3 additions & 2 deletions src/test/php/ConsoleOutputStreamTest.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\streams\OutputStream;
/**
* Test for stubbles\console\ConsoleOutputStream.
*
Expand All @@ -21,7 +22,7 @@ class ConsoleOutputStreamTest extends \PHPUnit_Framework_TestCase
public function returnsInstanceOfOutputStreamForOut()
{
assertInstanceOf(
'stubbles\streams\OutputStream',
OutputStream::class,
ConsoleOutputStream::forOut()
);
}
Expand All @@ -42,7 +43,7 @@ public function alwaysReturnsSameInstanceForOut()
public function returnsInstanceOfOutputStreamForError()
{
assertInstanceOf(
'stubbles\streams\OutputStream',
OutputStream::class,
ConsoleOutputStream::forError()
);
}
Expand Down
8 changes: 5 additions & 3 deletions src/test/php/ConsoleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
use bovigo\callmap\NewInstance;
use stubbles\input\errors\ParamErrors;
use stubbles\lang\reflect;
use stubbles\streams\InputStream;
use stubbles\streams\OutputStream;
/**
* Test for stubbles\console\Console.
*
Expand Down Expand Up @@ -49,9 +51,9 @@ class ConsoleTest extends \PHPUnit_Framework_TestCase
*/
public function setUp()
{
$this->inputStream = NewInstance::of('stubbles\streams\InputStream');
$this->outputStream = NewInstance::of('stubbles\streams\OutputStream');
$this->errorStream = NewInstance::of('stubbles\streams\OutputStream');
$this->inputStream = NewInstance::of(InputStream::class);
$this->outputStream = NewInstance::of(OutputStream::class);
$this->errorStream = NewInstance::of(OutputStream::class);
$this->console = new Console(
$this->inputStream,
$this->outputStream,
Expand Down
5 changes: 3 additions & 2 deletions src/test/php/creator/ClassFileCreatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use bovigo\callmap;
use bovigo\callmap\NewInstance;
use org\bovigo\vfs\vfsStream;
use stubbles\console\Console;
use stubbles\lang\ResourceLoader;
use stubbles\lang\Rootpath;
/**
Expand Down Expand Up @@ -50,7 +51,7 @@ public function setUp()
{
$this->root = vfsStream::setup();
$this->rootpath = new Rootpath($this->root->url());
$this->console = NewInstance::stub('stubbles\console\Console');
$this->console = NewInstance::stub(Console::class);
$this->classFileCreator = new ClassFileCreator(
$this->console,
$this->rootpath,
Expand Down Expand Up @@ -124,7 +125,7 @@ public function run()
*/
public function skipsClassCreationIfClassAlreadyExists()
{
$this->classFileCreator->create('stubbles\console\creator\ClassFileCreator');
$this->classFileCreator->create(ClassFileCreator::class);
assertFalse(
file_exists($this->rootpath->to('src/main/php/stubbles/console/creator/ClassFileCreator.php'))
);
Expand Down
11 changes: 6 additions & 5 deletions src/test/php/creator/ConsoleAppCreatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
namespace stubbles\console\creator;
use bovigo\callmap;
use bovigo\callmap\NewInstance;
use stubbles\console\Console;
use stubbles\input\ValueReader;
use stubbles\lang\Rootpath;
/**
Expand Down Expand Up @@ -50,10 +51,10 @@ class ConsoleAppCreatorTest extends \PHPUnit_Framework_TestCase
*/
public function setUp()
{
$this->console = NewInstance::stub('stubbles\console\Console');
$this->classFile = NewInstance::stub('stubbles\console\creator\ClassFileCreator');
$this->scriptFile = NewInstance::stub('stubbles\console\creator\ScriptFileCreator');
$this->testFile = NewInstance::stub('stubbles\console\creator\TestFileCreator');
$this->console = NewInstance::stub(Console::class);
$this->classFile = NewInstance::stub(ClassFileCreator::class);
$this->scriptFile = NewInstance::stub(ScriptFileCreator::class);
$this->testFile = NewInstance::stub(TestFileCreator::class);
$this->consoleAppCreator = new ConsoleAppCreator(
$this->console,
$this->classFile,
Expand Down Expand Up @@ -92,7 +93,7 @@ public function returnsExitCodeZeroOnSuccess()
public function canCreateInstance()
{
assertInstanceOf(
'stubbles\console\creator\ConsoleAppCreator',
ConsoleAppCreator::class,
ConsoleAppCreator::create(new Rootpath())
);
}
Expand Down
3 changes: 2 additions & 1 deletion src/test/php/creator/ScriptFileCreatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use bovigo\callmap;
use bovigo\callmap\NewInstance;
use org\bovigo\vfs\vfsStream;
use stubbles\console\Console;
use stubbles\lang\ResourceLoader;
use stubbles\lang\Rootpath;
/**
Expand Down Expand Up @@ -45,7 +46,7 @@ class ScriptFileCreatorTest extends \PHPUnit_Framework_TestCase
public function setUp()
{
$this->rootpath = new Rootpath(vfsStream::setup()->url());
$this->console = NewInstance::stub('stubbles\console\Console');
$this->console = NewInstance::stub(Console::class);
$this->scriptFileCreator = new ScriptFileCreator(
$this->console,
$this->rootpath,
Expand Down
3 changes: 2 additions & 1 deletion src/test/php/creator/TestFileCreatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use bovigo\callmap;
use bovigo\callmap\NewInstance;
use org\bovigo\vfs\vfsStream;
use stubbles\console\Console;
use stubbles\lang\ResourceLoader;
use stubbles\lang\Rootpath;
/**
Expand Down Expand Up @@ -50,7 +51,7 @@ public function setUp()
{
$this->root = vfsStream::setup();
$this->rootpath = new Rootpath($this->root->url());
$this->console = NewInstance::stub('stubbles\console\Console');
$this->console = NewInstance::stub(Console::class);
$this->testFileCreator = new TestFileCreator(
$this->console,
$this->rootpath,
Expand Down
9 changes: 6 additions & 3 deletions src/test/php/input/RequestParserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@
use bovigo\callmap\NewInstance;
use stubbles\console\ConsoleAppException;
use stubbles\input\ValueReader;
use stubbles\input\broker\RequestBroker;
use stubbles\input\console\ConsoleRequest;
use stubbles\input\errors\ParamErrors;
use stubbles\input\errors\messages\ParamErrorMessages;
use stubbles\streams\memory\MemoryOutputStream;
/**
* Test for stubbles\console\input\RequestParser.
Expand Down Expand Up @@ -52,9 +55,9 @@ class RequestParserTest extends \PHPUnit_Framework_TestCase
*/
public function setUp()
{
$this->consoleRequest = NewInstance::of('stubbles\input\console\ConsoleRequest');
$this->requestBroker = NewInstance::stub('stubbles\input\broker\RequestBroker');
$this->paramErrorMessages = NewInstance::of('stubbles\input\errors\messages\ParamErrorMessages');
$this->consoleRequest = NewInstance::of(ConsoleRequest::class);
$this->requestBroker = NewInstance::stub(RequestBroker::class);
$this->paramErrorMessages = NewInstance::of(ParamErrorMessages::class);
$this->requestParser = new RequestParser(
$this->consoleRequest,
$this->requestBroker,
Expand Down
Loading

0 comments on commit ef45262

Please sign in to comment.