protected function setUp() { parent::setUp(); $grantTypeFactory = new GrantTypeFactory(); $grantTypeFactory->add(new TestImplicit()); Environment::getContainer()->set('oauth2_grant_type_factory', $grantTypeFactory); }
/** * @expectedException \RuntimeException */ public function testCommandFileExists() { $command = $this->getMockBuilder('PSX\\Console\\Generate\\ControllerCommand')->setConstructorArgs(array(Environment::getContainer()))->setMethods(array('makeDir', 'writeFile', 'isDir', 'isFile'))->getMock(); $command->expects($this->at(0))->method('isDir')->with($this->equalTo('library' . DIRECTORY_SEPARATOR . 'Acme' . DIRECTORY_SEPARATOR . 'Foo'))->will($this->returnValue(false)); $command->expects($this->at(1))->method('makeDir')->with($this->equalTo('library' . DIRECTORY_SEPARATOR . 'Acme' . DIRECTORY_SEPARATOR . 'Foo')); $command->expects($this->at(2))->method('isFile')->with($this->equalTo('library' . DIRECTORY_SEPARATOR . 'Acme' . DIRECTORY_SEPARATOR . 'Foo' . DIRECTORY_SEPARATOR . 'Bar.php'))->will($this->returnValue(true)); $command->expects($this->never())->method('writeFile'); $commandTester = new CommandTester($command); $commandTester->execute(array('namespace' => 'Acme\\Foo\\Bar', 'services' => 'connection,template')); }
protected function setUp() { parent::setUp(); $grantTypeFactory = new GrantTypeFactory(); $grantTypeFactory->add(new TestAuthorizationCode()); $grantTypeFactory->add(new TestClientCredentials()); $grantTypeFactory->add(new TestImplicit()); $grantTypeFactory->add(new TestPassword()); $grantTypeFactory->add(new TestRefreshToken()); Environment::getContainer()->set('oauth2_grant_type_factory', $grantTypeFactory); }
public function testCommand() { $command = Environment::getService('console')->find('container'); $commandTester = new CommandTester($command); $commandTester->execute(array()); $serviceIds = Environment::getContainer()->getServiceIds(); $response = $commandTester->getDisplay(); foreach ($serviceIds as $serviceId) { $this->assertTrue(strpos($response, $serviceId) !== false, $serviceId); } }
public function testGet() { $container = Environment::getContainer(); // command $this->assertInstanceOf('PSX\\Dispatch\\CommandFactoryInterface', $container->get('command_factory')); $this->assertInstanceOf('PSX\\Command\\OutputInterface', $container->get('command_output')); $this->assertInstanceOf('PSX\\Command\\Executor', $container->get('executor')); // console $this->assertInstanceOf('Symfony\\Component\\Console\\Application', $container->get('console')); $this->assertInstanceOf('PSX\\Console\\ReaderInterface', $container->get('console_reader')); // controller $this->assertInstanceOf('PSX\\Dispatch\\ControllerFactoryInterface', $container->get('application_stack_factory')); $this->assertInstanceOf('PSX\\Dispatch\\ControllerFactoryInterface', $container->get('controller_factory')); $this->assertInstanceOf('PSX\\Dispatch\\SenderInterface', $container->get('dispatch_sender')); $this->assertInstanceOf('PSX\\Loader\\LocationFinderInterface', $container->get('loader_location_finder')); $this->assertInstanceOf('PSX\\Loader\\CallbackResolverInterface', $container->get('loader_callback_resolver')); $this->assertInstanceOf('PSX\\Loader', $container->get('loader')); $this->assertInstanceOf('PSX\\Dispatch\\RequestFactoryInterface', $container->get('request_factory')); $this->assertInstanceOf('PSX\\Dispatch\\ResponseFactoryInterface', $container->get('response_factory')); $this->assertInstanceOf('PSX\\Dispatch', $container->get('dispatch')); $this->assertInstanceOf('PSX\\Loader\\RoutingParserInterface', $container->get('routing_parser')); $this->assertInstanceOf('PSX\\Loader\\ReverseRouter', $container->get('reverse_router')); // data $this->assertInstanceOf('PSX\\Data\\ReaderFactory', $container->get('reader_factory')); $this->assertInstanceOf('PSX\\Data\\WriterFactory', $container->get('writer_factory')); $this->assertInstanceOf('PSX\\Data\\Transformer\\TransformerManager', $container->get('transformer_manager')); $this->assertInstanceOf('PSX\\Data\\Record\\ImporterManager', $container->get('importer_manager')); $this->assertInstanceOf('PSX\\Data\\Schema\\SchemaManagerInterface', $container->get('schema_manager')); $this->assertInstanceOf('PSX\\Data\\Schema\\ValidatorInterface', $container->get('schema_validator')); $this->assertInstanceOf('PSX\\Data\\Schema\\Assimilator', $container->get('schema_assimilator')); $this->assertInstanceOf('PSX\\Data\\Record\\FactoryFactory', $container->get('record_factory_factory')); $this->assertInstanceOf('PSX\\Data\\Importer', $container->get('importer')); $this->assertInstanceOf('PSX\\Data\\Extractor', $container->get('extractor')); $this->assertInstanceOf('PSX\\Data\\SerializerInterface', $container->get('serializer')); // default $this->assertInstanceOf('PSX\\Config', $container->get('config')); $this->assertInstanceOf('PSX\\Http', $container->get('http')); $this->assertInstanceOf('PSX\\Session', $container->get('session')); if (Environment::hasConnection()) { $this->assertInstanceOf('Doctrine\\DBAL\\Connection', $container->get('connection')); $this->assertInstanceOf('PSX\\Sql\\TableManager', $container->get('table_manager')); } $this->assertInstanceOf('PSX\\TemplateInterface', $container->get('template')); $this->assertInstanceOf('PSX\\Validate', $container->get('validate')); $this->assertInstanceOf('PSX\\Dependency\\ObjectBuilderInterface', $container->get('object_builder')); $this->assertInstanceOf('PSX\\Cache\\CacheItemPoolInterface', $container->get('cache')); $this->assertInstanceOf('Psr\\Log\\LoggerInterface', $container->get('logger')); // event $this->assertInstanceOf('Symfony\\Component\\EventDispatcher\\EventDispatcherInterface', $container->get('event_dispatcher')); }
public function testExecute() { $memory = new Output\Memory(); $output = new Output\Composite(array($memory, new Output\Logger(Environment::getService('logger')))); Environment::getContainer()->set('command_output', $output); $response = $this->sendRequest('http://127.0.0.1/command?command=' . urlencode('PSX\\Command\\Foo\\Command\\FooCommand'), 'POST', ['Content-Type' => 'application/json', 'Accept' => 'application/json'], '{"foo": "bar"}'); $data = Json::decode((string) $response->getBody()); $messages = $memory->getMessages(); $this->assertArrayHasKey('output', $data); $this->assertEquals(2, count($messages)); $lines = explode("\n", trim($data['output'])); foreach ($lines as $key => $line) { $this->assertArrayHasKey($key, $messages); $this->assertContains(trim($messages[$key]), $line); } }
public function testCommandStdin() { $memory = new Output\Memory(); Environment::getContainer()->set('command_output', $memory); $stream = fopen('php://memory', 'r+'); fwrite($stream, '{"foo": "test"}'); rewind($stream); $command = Environment::getService('console')->find('command'); $command->setReader(new Reader\Stdin($stream)); $commandTester = new CommandTester($command); $commandTester->execute(array('cmd' => 'PSX\\Command\\Foo\\Command\\FooCommand', '--stdin' => true)); $messages = $memory->getMessages(); $this->assertEquals(2, count($messages)); $this->assertEquals('Some foo informations', rtrim($messages[0])); $this->assertEquals('Hello test', rtrim($messages[1])); }
protected function tearDown() { parent::tearDown(); Environment::getContainer()->set('transformer_manager', null); }
protected function setUp() { parent::setUp(); // use memory sender Environment::getContainer()->set('dispatch_sender', new Memory()); }
/** * Removes all used services so that a new instance of a service gets * created. This ensures that our test has no side effects. This behaviour * is for some services unwanted like i.e. the db connection since we dont * want to re-establish a db connection for every test. Such services can be * listed in the _protectedServices property */ protected function clearServices() { // set original config Environment::getContainer()->set('config', Environment::getConfig()); // remove services $serviceIds = Environment::getContainer()->getServiceIds(); foreach ($serviceIds as $serviceId) { if (!in_array($serviceId, $this->_protectedServices)) { Environment::getContainer()->set($serviceId, null); } } }
public function testCommandEmptyService() { $command = $this->getMockBuilder('PSX\\Console\\Generate\\ApiCommand')->setConstructorArgs(array(Environment::getContainer()))->setMethods(array('makeDir', 'writeFile'))->getMock(); $commandTester = new CommandTester($command); $commandTester->execute(array('namespace' => 'Acme\\Foo\\Bar')); }