本文整理汇总了PHP中PSX\Test\Environment::getContainer方法的典型用法代码示例。如果您正苦于以下问题:PHP Environment::getContainer方法的具体用法?PHP Environment::getContainer怎么用?PHP Environment::getContainer使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PSX\Test\Environment
的用法示例。
在下文中一共展示了Environment::getContainer方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: setUp
protected function setUp()
{
parent::setUp();
$grantTypeFactory = new GrantTypeFactory();
$grantTypeFactory->add(new TestImplicit());
Environment::getContainer()->set('oauth2_grant_type_factory', $grantTypeFactory);
}
示例2: testCommandFileExists
/**
* @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'));
}
示例3: setUp
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);
}
示例4: testCommand
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);
}
}
示例5: testGet
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'));
}
示例6: testExecute
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);
}
}
示例7: testCommandStdin
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]));
}
示例8: tearDown
protected function tearDown()
{
parent::tearDown();
Environment::getContainer()->set('transformer_manager', null);
}
示例9: setUp
protected function setUp()
{
parent::setUp();
// use memory sender
Environment::getContainer()->set('dispatch_sender', new Memory());
}
示例10: clearServices
/**
* 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);
}
}
}
示例11: testCommandEmptyService
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'));
}