本文整理汇总了PHP中Mockery::on方法的典型用法代码示例。如果您正苦于以下问题:PHP Mockery::on方法的具体用法?PHP Mockery::on怎么用?PHP Mockery::on使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Mockery
的用法示例。
在下文中一共展示了Mockery::on方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testCreateMethodDescriptorFromVariousNotations
/**
* @param string $notation
* @param string $returnType
* @param string $name
* @param string[] $arguments
* @param string $description
*
* @dataProvider provideNotations
* @covers phpDocumentor\Descriptor\Builder\Reflector\Tags\MethodAssembler::create
* @covers phpDocumentor\Descriptor\Builder\Reflector\Tags\MethodAssembler::createArgumentDescriptorForMagicMethod
*/
public function testCreateMethodDescriptorFromVariousNotations($notation, $returnType, $name, $arguments = array(), $description = '')
{
$this->builder->shouldReceive('buildDescriptor')->with(m::on(function (TypeCollection $value) use($returnType) {
return $value[0] == $returnType;
}))->andReturn(new Collection(array($returnType)));
foreach ($arguments as $argument) {
list($argumentType, $argumentName, $argumentDefault) = $argument;
$this->builder->shouldReceive('buildDescriptor')->with(m::on(function (TypeCollection $value) use($argumentType) {
return $value[0] == $argumentType;
}))->andReturn(new Collection(array($argumentType)));
}
$tag = new MethodTag('method', $notation);
$descriptor = $this->fixture->create($tag);
$this->assertSame(1, $descriptor->getResponse()->getTypes()->count());
$this->assertSame($returnType, $descriptor->getResponse()->getTypes()->get(0));
$this->assertSame($name, $descriptor->getMethodName());
$this->assertSame($description, $descriptor->getDescription());
$this->assertSame(count($arguments), $descriptor->getArguments()->count());
foreach ($arguments as $argument) {
list($argumentType, $argumentName, $argumentDefault) = $argument;
$this->assertSame($argumentType, $descriptor->getArguments()->get($argumentName)->getTypes()->get(0));
$this->assertSame($argumentName, $descriptor->getArguments()->get($argumentName)->getName());
$this->assertSame($argumentDefault, $descriptor->getArguments()->get($argumentName)->getDefault());
}
}
示例2: testSend
public function testSend()
{
$mockException = \Mockery::mock('\\ErrorException');
$mockRequest = \Mockery::mock('\\Symfony\\Component\\HttpFoundation\\Request');
$mockContainer = \Mockery::mock('\\Symfony\\Component\\DependencyInjection\\ContainerInterface');
$mockTemplating = \Mockery::mock('Symfony\\Component\\Templating\\EngineInterface');
$mockEd = \Mockery::mock('\\Symfony\\Component\\EventDispatcher\\EventDispatcherInterface');
$mockMailer = \Mockery::mock('\\Swift_Mailer');
$mockTransport = \Mockery::mock('\\Swift_Transport');
$mockSpool = \Mockery::mock('\\Swift_Transport_SpoolTransport');
$mockMemSpool = \Mockery::mock('\\Swift_MemorySpool');
$mockHeaders = \Mockery::mock('\\Symfony\\Component\\DependencyInjection\\ParameterBag\\ParameterBagInterface');
$mockHeaders->shouldReceive('get')->once()->with('host')->andReturn('xyz');
$mockEd->shouldReceive('dispatch')->once()->with('ehough.bundle.emailErrors.preMail', \Mockery::on(function ($event) {
return $event instanceof GenericEvent && is_array($event->getSubject()) && $event->getArgument('shouldSend') === true;
}));
$mockRequest->headers = $mockHeaders;
$mockContainer->shouldReceive('get')->once()->with('templating')->andReturn($mockTemplating);
$mockContainer->shouldReceive('get')->once()->with('mailer')->andReturn($mockMailer);
$mockContainer->shouldReceive('get')->once()->with('swiftmailer.transport.real')->andReturn($mockTransport);
$mockContainer->shouldReceive('get')->once()->with('event_dispatcher')->andReturn($mockEd);
$context = array('foo' => 'bar');
$mockTemplating->shouldReceive('render')->once()->with('EhoughEmailErrorsBundle::mail.html.twig', \Mockery::on(function ($arg) {
return is_array($arg) && $arg['exception'] instanceof \Symfony\Component\Debug\Exception\FlattenException && $arg['request'] instanceof Request && is_array($arg['context']);
}))->andReturn('foobar');
$this->_sut->setContainer($mockContainer);
$mockMailer->shouldReceive('send')->once()->with(\Mockery::on(function ($arg) {
return $arg instanceof \Swift_Message && $arg->getSubject() === '[xyz] Error 500: ' && $arg->getBody() === 'foobar';
}));
$mockMailer->shouldReceive('getTransport')->once()->andReturn($mockSpool);
$mockSpool->shouldReceive('getSpool')->once()->andReturn($mockMemSpool);
$mockMemSpool->shouldReceive('flushQueue')->once()->with($mockTransport);
$this->_sut->sendMail($mockException, $mockRequest, $context, true);
}
示例3: test_process_upsertEventsGetCalled
public function test_process_upsertEventsGetCalled()
{
$mockPdoFacade = \Mockery::mock('\\TestDbAcle\\Db\\Mysql\\Pdo\\PdoFacade');
$dataTree = new \TestDbAcle\Psv\PsvTree();
$dataTree->addTable(new \TestDbAcle\Psv\Table\Table('user', array(array("user_id" => "10", "first_name" => "john", "last_name" => "miller"), array("user_id" => "20", "first_name" => "stu", "last_name" => "Smith"))));
$self = $this;
// we need to pass this in for PHP version<5.4
$checkUpserterClosure = function ($upserter) use($self) {
$self->assertTrue($upserter instanceof \TestDbAcle\Db\DataInserter\Sql\InsertBuilder);
$self->assertEquals('user', $upserter->getTableName());
return true;
};
$testListener1 = \Mockery::mock('\\TestDbAcle\\Db\\DataInserter\\UpsertListenerInterface');
$testListener2 = \Mockery::mock('\\TestDbAcle\\Db\\DataInserter\\UpsertListenerInterface');
$mockPdoFacade->shouldReceive('clearTable')->once()->with('user')->ordered();
$mockPdoFacade->shouldReceive('executeSql')->once()->with("INSERT INTO `user` ( `user_id`, `first_name`, `last_name` ) VALUES ( '10', 'john', 'miller' )")->ordered();
$testListener1->shouldReceive('afterUpsert')->once()->with(\Mockery::on($checkUpserterClosure));
$testListener2->shouldReceive('afterUpsert')->once()->with(\Mockery::on($checkUpserterClosure));
$mockPdoFacade->shouldReceive('executeSql')->once()->with("INSERT INTO `user` ( `user_id`, `first_name`, `last_name` ) VALUES ( '20', 'stu', 'Smith' )")->ordered();
$testListener1->shouldReceive('afterUpsert')->once()->with(\Mockery::on($checkUpserterClosure));
$testListener2->shouldReceive('afterUpsert')->once()->with(\Mockery::on($checkUpserterClosure));
$dataInserter = new \TestDbAcle\Db\DataInserter\DataInserter($mockPdoFacade, new \TestDbAcle\Db\DataInserter\Factory\UpsertBuilderFactory($mockPdoFacade));
$dataInserter->addUpsertListener($testListener1);
$dataInserter->addUpsertListener($testListener2);
$dataInserter->process($dataTree);
}
示例4: testWillReturnATableModelAfterConvertingIndexAndFieldModelsFromPersistenceToDomain
/**
* Will return a table model after converting index and field models from persistence to domain.
*
* @runInSeparateProcess
* @preserveGlobalState disabled
*/
public function testWillReturnATableModelAfterConvertingIndexAndFieldModelsFromPersistenceToDomain()
{
/** @var \Mockery\MockInterface|SchemaMapper $mapper */
$mapper = \Mockery::mock('\\DatabaseInspect\\Domain\\Mappers\\SchemaMapper')->makePartial();
// define input
$tableName = 'table_1';
$fieldEntries = [\Mockery::mock(TableField::class), \Mockery::mock(TableField::class), \Mockery::mock(TableField::class)];
$indexEntries = [\Mockery::mock(TableIndex::class), \Mockery::mock(TableIndex::class)];
// define internal DTO -> Domain model translators
$indexCollection = \Mockery::mock(TableIndexCollection::class);
$fieldCollection = \Mockery::mock(TableFieldCollection::class);
$mapper->shouldReceive('buildTableFieldCollectionFromPersistence')->once()->with($fieldEntries)->andReturn($fieldCollection);
$mapper->shouldReceive('buildTableIndexCollectionFromPersistence')->once()->with($indexEntries)->andReturn($indexCollection);
// define static Table build asserts and expectation
$buildOutput = \Mockery::mock(Table::class);
$closureCheckTableNamePassedToTableBuild = \Mockery::on(function (StringLiteral $tableName) {
return $tableName->toNative() === 'table_1';
});
$request = \Mockery::mock('overload:DatabaseInspect\\Domain\\Models\\Table');
$request->shouldReceive('build')->once()->with($closureCheckTableNamePassedToTableBuild, $fieldCollection, $indexCollection)->andReturn($buildOutput);
// perform action
/** @var Table $output */
$response = $mapper->buildTableFromPersistence($tableName, $fieldEntries, $indexEntries);
// assert expectation
static::assertSame($buildOutput, $response);
}
示例5: testCanSendNormalRequest
public function testCanSendNormalRequest()
{
$this->streamMock->shouldReceive('streamContextCreate')->once()->with(m::on(function ($arg) {
if (!isset($arg['http']) || !isset($arg['ssl'])) {
return false;
}
if ($arg['http'] !== ['method' => 'GET', 'timeout' => 60, 'ignore_errors' => true, 'header' => 'X-foo: bar']) {
return false;
}
$caInfo = array_diff_assoc($arg['ssl'], ['verify_peer' => true, 'verify_peer_name' => true, 'allow_self_signed' => true]);
if (count($caInfo) !== 1) {
return false;
}
if (1 !== preg_match('/.+\\/certs\\/DigiCertHighAssuranceEVRootCA\\.pem$/', $caInfo['cafile'])) {
return false;
}
return true;
}))->andReturn(null);
$this->streamMock->shouldReceive('getResponseHeaders')->once()->andReturn(explode("\n", trim($this->fakeRawHeader)));
$this->streamMock->shouldReceive('fileGetContents')->once()->with('http://foo.com/')->andReturn($this->fakeRawBody);
$this->streamClient->addRequestHeader('X-foo', 'bar');
$responseBody = $this->streamClient->send('http://foo.com/');
$this->assertEquals($responseBody, $this->fakeRawBody);
$this->assertEquals($this->streamClient->getResponseHeaders(), $this->fakeHeadersAsArray);
$this->assertEquals(200, $this->streamClient->getResponseHttpStatusCode());
}
示例6: verifyCorrectLoadingRoutesForType
protected function verifyCorrectLoadingRoutesForType($type)
{
$basePath = 'base/path';
$moduleARoutePrefix = 'sample-prefix-module-a';
$moduleBRoutePrefix = 'sample-prefix-module-b';
$moduleARouteFile = 'moduleA/routes.php';
$moduleBRouteFile = 'moduleB/routes.php';
$router = m::mock(Router::class);
$moduleA = m::mock(stdClass::class);
$moduleB = m::mock(stdClass::class);
$moduleA->shouldReceive('routingControllerNamespace')->once()->withNoArgs()->andReturn('moduleAControllerNamespace');
$moduleB->shouldReceive('routingControllerNamespace')->once()->withNoArgs()->andReturn('moduleBControllerNamespace');
$this->modular->shouldReceive('withRoutes')->once()->andReturn(collect([$moduleA, $moduleB]));
$router->shouldReceive('group')->once()->with(['namespace' => 'moduleAControllerNamespace'], m::on(function ($closure) use($router) {
call_user_func($closure, $router);
return true;
}));
$this->app->shouldReceive('basePath')->times(2)->andReturn($basePath);
$moduleA->shouldReceive('routePrefix')->once()->with(compact('type'))->andReturn($moduleARoutePrefix);
$moduleA->shouldReceive('routesFilePath')->once()->with($moduleARoutePrefix)->andReturn($moduleARouteFile);
$file = m::mock(stdClass::class);
$this->app->shouldReceive('offsetGet')->times(2)->with('files')->andReturn($file);
$file->shouldReceive('getRequire')->once()->with($basePath . DIRECTORY_SEPARATOR . $moduleARouteFile);
$router->shouldReceive('group')->once()->with(['namespace' => 'moduleBControllerNamespace'], m::on(function ($closure) use($router) {
call_user_func($closure, $router);
return true;
}));
$moduleB->shouldReceive('routePrefix')->once()->with(compact('type'))->andReturn($moduleBRoutePrefix);
$moduleB->shouldReceive('routesFilePath')->once()->with($moduleBRoutePrefix)->andReturn($moduleBRouteFile);
$file->shouldReceive('getRequire')->once()->with($basePath . DIRECTORY_SEPARATOR . $moduleBRouteFile);
$this->assertSame(null, $this->modular->loadRoutes($router, $type));
}
示例7: it_can_retry_a_message
/**
* @test
*/
public function it_can_retry_a_message()
{
$id = 1234;
$body = 'test';
$routingKey = 'foo';
$priority = 3;
$headers = ['foo' => 'bar'];
/** @var MockInterface|EnvelopeInterface $envelope */
$envelope = Mock::mock(EnvelopeInterface::class);
$envelope->shouldReceive('getDeliveryTag')->andReturn($id);
$envelope->shouldReceive('getBody')->andReturn($body);
$envelope->shouldReceive('getRoutingKey')->andReturn($routingKey);
$envelope->shouldReceive('getPriority')->andReturn($priority);
$envelope->shouldReceive('getHeaders')->andReturn($headers);
$envelope->shouldReceive('getContentType')->andReturn(MessageProperties::CONTENT_TYPE_BASIC);
$envelope->shouldReceive('getDeliveryMode')->andReturn(MessageProperties::DELIVERY_MODE_PERSISTENT);
$attempt = 2;
$publisher = $this->createPublisherMock();
$publisher->shouldReceive('publish')->once()->with(Mock::on(function (Message $retryMessage) use($envelope, $attempt) {
$this->assertSame($envelope->getDeliveryTag(), $retryMessage->getId(), 'Delivery tag of the retry-message is not the same');
$this->assertSame($envelope->getBody(), $retryMessage->getBody(), 'Body of the retry-message is not the same');
$this->assertSame($envelope->getRoutingKey(), $retryMessage->getRoutingKey(), 'Routing key of the retry-message is not the same');
$this->assertArraySubset($envelope->getHeaders(), $retryMessage->getHeaders(), 'Headers are not properly cloned');
$this->assertSame($retryMessage->getPriority(), $envelope->getPriority() - 1, 'Priority should decrease with 1');
$this->assertSame($attempt, $retryMessage->getHeader(RetryProcessor::PROPERTY_KEY), 'There should be an "attempt" header in the retry message');
return true;
}))->andReturn(true);
$strategy = new DeprioritizeStrategy($publisher);
$result = $strategy->retry($envelope, $attempt);
$this->assertTrue($result);
}
示例8: testCanSendNormalRequest
public function testCanSendNormalRequest()
{
$this->streamMock->shouldReceive('streamContextCreate')->once()->with(\Mockery::on(function ($arg) {
if (!isset($arg['http']) || !isset($arg['ssl'])) {
return false;
}
if ($arg['http'] !== array('method' => 'GET', 'timeout' => 60, 'ignore_errors' => true, 'header' => 'X-foo: bar')) {
return false;
}
if ($arg['ssl']['verify_peer'] !== true) {
return false;
}
if (false === preg_match('/.fb_ca_chain_bundle\\.crt$/', $arg['ssl']['cafile'])) {
return false;
}
return true;
}))->andReturn(null);
$this->streamMock->shouldReceive('getResponseHeaders')->once()->andReturn(explode("\n", trim($this->fakeRawHeader)));
$this->streamMock->shouldReceive('fileGetContents')->once()->with('http://foo.com/')->andReturn($this->fakeRawBody);
$this->streamClient->addRequestHeader('X-foo', 'bar');
$responseBody = $this->streamClient->send('http://foo.com/');
$this->assertEquals($responseBody, $this->fakeRawBody);
$this->assertEquals($this->streamClient->getResponseHeaders(), $this->fakeHeadersAsArray);
$this->assertEquals(200, $this->streamClient->getResponseHttpStatusCode());
}
示例9: testGettingUserDetails
public function testGettingUserDetails()
{
$server = m::mock('Wheniwork\\OAuth1\\Client\\Server\\Intuit[createHttpClient,protocolHeader]', [$this->getMockClientCredentials()]);
$temporaryCredentials = m::mock('League\\OAuth1\\Client\\Credentials\\TokenCredentials');
$temporaryCredentials->shouldReceive('getIdentifier')->andReturn('tokencredentialsidentifier');
$temporaryCredentials->shouldReceive('getSecret')->andReturn('tokencredentialssecret');
$server->shouldReceive('createHttpClient')->andReturn($client = m::mock('stdClass'));
$me = $this;
$client->shouldReceive('get')->with('https://appcenter.intuit.com/api/v1/user/current', m::on(function ($headers) use($me) {
$me->assertTrue(isset($headers['Authorization']));
// OAuth protocol specifies a strict number of
// headers should be sent, in the correct order.
// We'll validate that here.
$pattern = '/OAuth oauth_consumer_key=".*?", oauth_nonce="[a-zA-Z0-9]+", oauth_signature_method="HMAC-SHA1", oauth_timestamp="\\d{10}", oauth_version="1.0", oauth_token="tokencredentialsidentifier", oauth_signature=".*?"/';
$matches = preg_match($pattern, $headers['Authorization']);
$me->assertEquals(1, $matches, 'Asserting that the authorization header contains the correct expression.');
return true;
}))->once()->andReturn($request = m::mock('stdClass'));
$request->shouldReceive('send')->once()->andReturn($response = m::mock('stdClass'));
$response->shouldReceive('xml')->once()->andReturn($this->getUserPayload());
$user = $server->getUserDetails($temporaryCredentials);
$this->assertInstanceOf('League\\OAuth1\\Client\\Server\\User', $user);
$this->assertEquals('John Doe', $user->name);
$this->assertEquals(null, $server->getUserUid($temporaryCredentials));
$this->assertEquals('JohnDoe@g88.net', $server->getUserEmail($temporaryCredentials));
}
示例10: testWriterAddsTheSqlFormatterExtension
public function testWriterAddsTheSqlFormatterExtension()
{
$this->twigEnvironment->shouldReceive('addExtension')->once()->with(m::on(function ($argument) {
return $argument instanceof SqlFormatterExtension;
}));
$writer = new Writer($this->fileSystem, $this->twigEnvironment, $this->twigEngine);
}
示例11: setUp
/**
* Init tuff.
*/
public function setUp()
{
$this->validSwiftMessage = m::on(function ($message) {
return $message instanceof \Swift_Message;
});
$this->templName = 'myTemplate';
$this->templ = m::mock('Symfony\\Bundle\\FrameworkBundle\\Templating\\EngineInterface')->shouldReceive('render')->once()->with($this->templName, array())->andReturn("subject\nBody\nmoreBody")->getMock();
}
示例12: testClearAll
public function testClearAll()
{
$validKeys = SessionStorage::$validKeys;
$storage = m::mock('Happyr\\LinkedIn\\Storage\\SessionStorage[clear]')->shouldReceive('clear')->times(count($validKeys))->with(m::on(function ($arg) use($validKeys) {
return in_array($arg, $validKeys);
}))->getMock();
$storage->clearAll();
}
示例13: assertEqualAggregatedRoot
protected function assertEqualAggregatedRoot(RecordsMessages $expected)
{
return m::on(function (RecordsMessages $actual) use($expected) {
$actual = clone $actual;
$actual->eraseMessages();
return Assertions::equalTo($expected)->evaluate($actual, '', true);
});
}
示例14: stubCreateDequeueMessage
protected function stubCreateDequeueMessage($body, $id, $handle)
{
$this->factory->shouldReceive('createMessage')->once()->with($body, m::on(function ($opts) use($id, $handle) {
$meta = ['Attributes' => [], 'MessageAttributes' => [], 'MessageId' => $id, 'ReceiptHandle' => $handle];
$validator = isset($opts['validator']) && is_callable($opts['validator']);
return isset($opts['metadata']) && $opts['metadata'] === $meta && $validator;
}))->andReturn($this->messageA);
}
示例15: testFetchWithOptions
/**
* Tests that a clone of the provider's options are passed to ProviderResource::fetch().
*/
public function testFetchWithOptions()
{
$this->setOptions($options = \Mockery::mock(EncapsulatedOptions::class));
$this->provider->fetch(MockFactory::mockResource($this->provider)->shouldReceive('fetch')->with($this->connector, \Mockery::on(function (EncapsulatedOptions $argument) use($options) {
self::assertNotSame($options, $argument);
return get_class($options) === get_class($argument);
}))->getMock());
}