本文整理汇总了PHP中PSX\Test\Environment::getService方法的典型用法代码示例。如果您正苦于以下问题:PHP Environment::getService方法的具体用法?PHP Environment::getService怎么用?PHP Environment::getService使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PSX\Test\Environment
的用法示例。
在下文中一共展示了Environment::getService方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getEntityManager
protected function getEntityManager()
{
if (self::$em === null) {
self::$em = Environment::getService('entity_manager');
}
return self::$em;
}
示例2: setUp
protected function setUp()
{
if (!class_exists('MongoDB')) {
$this->markTestSkipped('MongoDB extension not available');
}
if (!self::$hasConnection) {
$this->markTestSkipped('MongoDB connection not available');
}
parent::setUp();
try {
$this->mongodb = Environment::getService('connector')->getConnection(3);
} catch (MongoConnectionException $e) {
self::$hasConnection = false;
$this->markTestSkipped('MongoDB connection not available');
}
$this->collection = $this->mongodb->createCollection('app_news');
$table = $this->getDataSet()->getTable('app_news');
$columns = $table->getTableMetaData()->getColumns();
for ($i = 0; $i < $table->getRowCount(); $i++) {
$row = array();
foreach ($columns as $name) {
$row[$name] = $table->getValue($i, $name);
}
$this->collection->insert($row);
}
}
示例3: getAuthorizationCode
protected function getAuthorizationCode($code, $state)
{
$testCase = $this->testCase;
$http = new Http(new Callback(function (RequestInterface $request) use($testCase) {
// api request
if ($request->getUri()->getPath() == '/api') {
$testCase->assertEquals('Basic czZCaGRSa3F0MzpnWDFmQmF0M2JW', (string) $request->getHeader('Authorization'));
$testCase->assertEquals('application/x-www-form-urlencoded', (string) $request->getHeader('Content-Type'));
$response = <<<TEXT
HTTP/1.1 200 OK
Content-Type: application/json;charset=UTF-8
Cache-Control: no-store
Pragma: no-cache
{
"access_token":"2YotnFZFEjr1zCsicMWpAA",
"token_type":"example",
"expires_in":3600,
"refresh_token":"tGzv3JOkF0XG5Qx2TlKWIA",
"example_parameter":"example_value"
}
TEXT;
} else {
throw new \RuntimeException('Invalid path');
}
return ResponseParser::convert($response, ResponseParser::MODE_LOOSE)->toString();
}));
$oauth = new AuthorizationCode($http, new Url('http://127.0.0.1/api'), Environment::getService('importer'));
$oauth->setClientPassword(ClientCredentialsTest::CLIENT_ID, ClientCredentialsTest::CLIENT_SECRET);
return $oauth;
}
示例4: testRequest
public function testRequest()
{
$testCase = $this;
$http = new Http(new Callback(function (RequestInterface $request) use($testCase) {
// api request
if ($request->getUri()->getPath() == '/api') {
$testCase->assertEquals('Basic czZCaGRSa3F0MzpnWDFmQmF0M2JW', (string) $request->getHeader('Authorization'));
$testCase->assertEquals('application/x-www-form-urlencoded', (string) $request->getHeader('Content-Type'));
$testCase->assertEquals('grant_type=authorization_code&code=SplxlOBeZQQYbYS6WxSbIA', (string) $request->getBody());
$response = <<<TEXT
HTTP/1.1 200 OK
Content-Type: application/json;charset=UTF-8
Cache-Control: no-store
Pragma: no-cache
{
"access_token":"2YotnFZFEjr1zCsicMWpAA",
"token_type":"example",
"expires_in":3600,
"example_parameter":"example_value"
}
TEXT;
} else {
throw new \RuntimeException('Invalid path');
}
return ResponseParser::convert($response, ResponseParser::MODE_LOOSE)->toString();
}));
$oauth = new AuthorizationCode($http, new Url('http://127.0.0.1/api'), Environment::getService('importer'));
$oauth->setClientPassword(self::CLIENT_ID, self::CLIENT_SECRET);
$accessToken = $oauth->getAccessToken('SplxlOBeZQQYbYS6WxSbIA');
$this->assertEquals('2YotnFZFEjr1zCsicMWpAA', $accessToken->getAccessToken());
$this->assertEquals('example', $accessToken->getTokenType());
$this->assertEquals(3600, $accessToken->getExpiresIn());
}
示例5: testGetForm
public function testGetForm()
{
$action = new Pipe();
$builder = new Builder();
$factory = Environment::getService('form_element_factory');
$action->configure($builder, $factory);
$this->assertInstanceOf('Fusio\\Impl\\Form\\Container', $builder->getForm());
}
示例6: doGet
protected function doGet(Version $version)
{
$this->testCase->assertEquals(12, $this->queryParameters->getProperty('startIndex'));
$this->testCase->assertEmpty($this->queryParameters->getProperty('bar'));
$this->testCase->assertEquals(8, $this->pathParameters->getProperty('fooId'));
$this->testCase->assertEmpty($this->pathParameters->getProperty('bar'));
return array('entry' => Environment::getService('table_manager')->getTable('PSX\\Sql\\TestTable')->getAll());
}
示例7: setUp
protected function setUp()
{
parent::setUp();
if (!Environment::hasConnection()) {
$this->markTestSkipped('Database connection not available');
}
$this->connection = Environment::getService('connection');
}
示例8: testFilter
public function testFilter()
{
$table = Environment::getService('table_manager')->getTable('PSX\\Sql\\TestTable');
$filter = new PrimaryKey($table);
$this->assertEquals(true, $filter->apply(1));
$this->assertEquals(false, $filter->apply(32));
// test error message
$this->assertEquals('%s does not exist in table', $filter->getErrorMessage());
}
示例9: getResource
protected function getResource()
{
$request = $this->getMock('PSX\\Http\\RequestInterface');
$response = $this->getMock('PSX\\Http\\ResponseInterface');
$context = new Context();
$context->set(Context::KEY_PATH, '/foo/bar');
$documentation = Environment::getService('controller_factory')->getController('PSX\\Controller\\Foo\\Application\\SchemaApi\\VersionViewController', $request, $response, $context)->getDocumentation();
return $documentation->getResource($documentation->getLatestVersion());
}
示例10: testClassNotExist
/**
* @expectedException \ReflectionException
*/
public function testClassNotExist()
{
$context = new Context();
$context->set(Context::KEY_SOURCE, 'Foo::bar');
$request = new Request(new Url('http://127.0.0.1'), 'GET');
$response = new Response();
$simple = new DependencyInjector(Environment::getService('controller_factory'));
$simple->resolve($request, $response, $context);
}
示例11: 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);
}
}
示例12: getConnection
public function getConnection()
{
if (!Environment::hasConnection()) {
$this->markTestSkipped('No database connection available');
}
if (self::$con === null) {
self::$con = Environment::getService('connection');
}
if ($this->connection === null) {
$this->connection = self::$con;
}
return $this->createDefaultDBConnection($this->connection->getWrappedConnection(), Environment::getService('config')->get('psx_sql_db'));
}
示例13: testTransform
public function testTransform()
{
$template = new Twig(Environment::getService('config'));
$template->setDir('tests/PSX/Template/twig');
$template->set('foo.twig.html');
$this->assertTrue($template->hasFile());
$this->assertTrue($template->isFileAvailable());
$this->assertFalse($template->isAbsoluteFile());
$this->assertEquals('foo.twig.html', $template->get());
$template->assign('foo', 'bar');
$content = $template->transform();
$this->assertEquals('Hello bar', $content);
}
示例14: testSerializeVersionedGreater
public function testSerializeVersionedGreater()
{
$author = new Serializer\TestAuthor();
$author->setName('bar');
$object = new Serializer\TestObjectVersioned();
$object->setTitle('foo');
$object->setAuthor($author);
$return = Environment::getService('serializer')->serialize($object, new Version(2));
$expect = array();
$expect['title'] = 'foo';
$expect['author'] = array();
$expect['author']['name'] = 'bar';
$this->assertEquals($expect, $return);
}
示例15: testExplicitTemplate
public function testExplicitTemplate()
{
$response = $this->sendRequest('http://127.0.0.1/view/explicit', 'GET', ['Accept' => 'text/html']);
$data = simplexml_load_string((string) $response->getBody());
$render = (double) $data->render;
$config = Environment::getService('config');
$base = (string) parse_url($config['psx_url'], PHP_URL_PATH);
$this->assertEquals('bar', $data->foo);
$this->assertTrue(!empty($data->self));
$this->assertEquals($config['psx_url'] . '/' . $config['psx_dispatch'], $data->url);
$this->assertEquals($base, $data->base);
$this->assertTrue($render > 0);
$this->assertEquals('tests/PSX/Controller/Foo/Resource', $data->location);
}