assertSame() public static method

Used on objects, it asserts that two variables reference the same object.
public static assertSame ( mixed $expected, mixed $actual, string $message = '' )
$expected mixed
$actual mixed
$message string
Esempio n. 1
0
 /**
  * Check if the message is requeued or not correctly.
  *
  * @dataProvider processMessageProvider
  */
 public function testProcessMessage($processFlag, $expectedMethod, $expectedRequeue = null)
 {
     $amqpConnection = $this->getMockBuilder('\\PhpAmqpLib\\Connection\\AMQPConnection')->disableOriginalConstructor()->getMock();
     $amqpChannel = $this->getMockBuilder('\\PhpAmqpLib\\Channel\\AMQPChannel')->disableOriginalConstructor()->getMock();
     $consumer = new Consumer($amqpConnection, $amqpChannel);
     $callbackFunction = function () use($processFlag) {
         return $processFlag;
     };
     // Create a callback function with a return value set by the data provider.
     $consumer->setCallback($callbackFunction);
     // Create a default message
     $amqpMessage = new AMQPMessage('foo body');
     $amqpMessage->delivery_info['channel'] = $amqpChannel;
     $amqpMessage->delivery_info['delivery_tag'] = 0;
     $amqpChannel->expects($this->any())->method('basic_reject')->will($this->returnCallback(function ($delivery_tag, $requeue) use($expectedMethod, $expectedRequeue) {
         \PHPUnit_Framework_Assert::assertSame($expectedMethod, 'basic_reject');
         // Check if this function should be called.
         \PHPUnit_Framework_Assert::assertSame($requeue, $expectedRequeue);
         // Check if the message should be requeued.
     }));
     $amqpChannel->expects($this->any())->method('basic_ack')->will($this->returnCallback(function ($delivery_tag) use($expectedMethod) {
         \PHPUnit_Framework_Assert::assertSame($expectedMethod, 'basic_ack');
         // Check if this function should be called.
     }));
     $consumer->processMessage($amqpMessage);
 }
 /**
  * Check if the message is requeued or not correctly.
  *
  * @dataProvider processMessageProvider
  */
 public function testProcessMessage($processFlag, $expectedMethod, $expectedRequeue = null)
 {
     $amqpConnection = $this->getMockBuilder('\\PhpAmqpLib\\Connection\\AMQPConnection')->disableOriginalConstructor()->getMock();
     $amqpChannel = $this->getMockBuilder('\\PhpAmqpLib\\Channel\\AMQPChannel')->disableOriginalConstructor()->getMock();
     $consumer = new MultipleConsumer($amqpConnection, $amqpChannel);
     $callback = function ($msg) use(&$lastQueue, $processFlag) {
         return $processFlag;
     };
     $consumer->setQueues(array('test-1' => array('callback' => $callback), 'test-2' => array('callback' => $callback)));
     // Create a default message
     $amqpMessage = new AMQPMessage('foo body');
     $amqpMessage->delivery_info['channel'] = $amqpChannel;
     $amqpMessage->delivery_info['delivery_tag'] = 0;
     $amqpChannel->expects($this->any())->method('basic_reject')->will($this->returnCallback(function ($delivery_tag, $requeue) use($expectedMethod, $expectedRequeue) {
         \PHPUnit_Framework_Assert::assertSame($expectedMethod, 'basic_reject');
         // Check if this function should be called.
         \PHPUnit_Framework_Assert::assertSame($requeue, $expectedRequeue);
         // Check if the message should be requeued.
     }));
     $amqpChannel->expects($this->any())->method('basic_ack')->will($this->returnCallback(function ($delivery_tag) use($expectedMethod) {
         \PHPUnit_Framework_Assert::assertSame($expectedMethod, 'basic_ack');
         // Check if this function should be called.
     }));
     $consumer->processQueueMessage('test-1', $amqpMessage);
     $consumer->processQueueMessage('test-2', $amqpMessage);
 }
 /**
  * @test
  * @dataProvider eventProvider
  */
 public function itInstallsASite($eventName, LifecycleEvent $event)
 {
     $dispatcher = $this->prophesize('Symfony\\Component\\EventDispatcher\\EventDispatcherInterface');
     $drupal = $this->generateDrupal();
     $processRunner = $this->prophesize('eLife\\IsolatedDrupalBehatExtension\\Process\\ProcessRunner');
     $listener = new InstallSiteListener($dispatcher->reveal(), $drupal, '/path/to/drush', $processRunner->reveal());
     $dispatcher->dispatch(InstallingSite::NAME, Argument::type('eLife\\IsolatedDrupalBehatExtension\\Event\\InstallingSite'))->shouldBeCalledTimes(1)->should(new CallbackPrediction(function (array $calls) use($drupal) {
         /** @var Call $call */
         $call = $calls[0];
         /** @var InstallingSite $event */
         $event = $call->getArguments()[1];
         $process = $event->getCommand()->getProcess();
         Assert::assertSame("'/path/to/drush' 'site-install' 'standard' " . "'--sites-subdir=localhost' '--account-name=admin' " . "'--account-pass=password' '--yes'", $process->getCommandLine());
         Assert::assertArrayHasKey('PHP_OPTIONS', $process->getEnv());
         Assert::assertSame('-d sendmail_path=' . `which true`, $process->getEnv()['PHP_OPTIONS']);
         Assert::assertSame($drupal->getPath(), $process->getWorkingDirectory());
     }));
     $processRunner->run(Argument::type('Symfony\\Component\\Process\\Process'))->shouldBeCalledTimes(1);
     $dispatcher->dispatch(SiteInstalled::NAME, Argument::type('eLife\\IsolatedDrupalBehatExtension\\Event\\SiteInstalled'))->shouldBeCalledTimes(1)->should(new CallbackPrediction(function (array $calls) use($drupal) {
         /** @var Call $call */
         $call = $calls[0];
         /** @var SiteInstalled $event */
         $event = $call->getArguments()[1];
         Assert::assertEquals($drupal, $event->getDrupal());
     }));
     $this->getDispatcher($listener)->dispatch($eventName, $event);
 }
 /**
  * Tests if an object has the required attributes and they have the correct value.
  *
  * Returns true, if and only if the object defines ALL attributes and they have the expected value
  *
  * @param object $other
  *
  * @return bool
  */
 protected function matches($other)
 {
     $this->result = [];
     $success = true;
     $reflection = new \ReflectionClass($other);
     $properties = $reflection->getDefaultProperties();
     foreach ($this->defaultAttributes as $prop => $value) {
         if (is_int($prop)) {
             $prop = $value;
             $value = null;
         }
         if (array_key_exists($prop, $properties)) {
             try {
                 \PHPUnit_Framework_Assert::assertSame($value, $properties[$prop]);
                 $this->result[$prop] = true;
             } catch (\PHPUnit_Framework_ExpectationFailedException $e) {
                 $message = $e->toString();
                 if ($comparisonFailure = $e->getComparisonFailure()) {
                     $message .= sprintf("\n%30sExpected: %s\n%30sActual  : %s\n", '', $comparisonFailure->getExpectedAsString(), '', $comparisonFailure->getActualAsString());
                 }
                 $this->result[$prop] = $message;
                 $success = false;
             }
         } else {
             $this->result[$prop] = 'Attribute is not defined.';
             $success = false;
         }
     }
     return $success;
 }
 /**
  * @inheritdoc
  */
 public function assertDataPersisted($name, array $data)
 {
     $alias = $this->convertNameToAlias($this->singularize($name));
     $class = $this->getEntityManager()->getClassMetadata($alias)->getName();
     $found = [];
     foreach ($data as $row) {
         $criteria = $this->applyMapping($this->getFieldMapping($class), $row);
         $criteria = $this->rowToEntityData($class, $criteria, false);
         $jsonArrayFields = $this->getJsonArrayFields($class, $criteria);
         $criteria = array_diff_key($criteria, $jsonArrayFields);
         $entity = $this->getEntityManager()->getRepository($class)->findOneBy($criteria);
         Assert::assertNotNull($entity, sprintf('The repository should find data of type "%s" with these criteria: %s', $alias, json_encode($criteria)));
         if (!empty($jsonArrayFields)) {
             // refresh json fields as they may have changed beforehand
             $this->getEntityManager()->refresh($entity);
             // json array fields can not be matched by the ORM (depends on driver and requires driver-specific operators),
             // therefore we need to check these separately
             $accessor = PropertyAccess::createPropertyAccessor();
             foreach ($jsonArrayFields as $field => $value) {
                 Assert::assertSame($value, $accessor->getValue($entity, $field));
             }
         }
         $found[] = $entity;
     }
     return $found;
 }
Esempio n. 6
0
 /**
  * @Then /^(?:the )?response code should be (\d+)$/
  */
 public function theResponseCodeShouldBe($code)
 {
     $this->getResponse();
     $expected = intval($code);
     $actual = intval($this->getResponse()->getStatusCode());
     Assertions::assertSame($expected, $actual);
 }
Esempio n. 7
0
 /**
  * Check if the message is requeued or not correctly.
  *
  * @dataProvider processMessageProvider
  */
 public function testProcessMessage($processFlag, $expectedMethod, $expectedRequeue = null)
 {
     $amqpConnection = $this->prepareAMQPConnection();
     $amqpChannel = $this->prepareAMQPChannel();
     $consumer = $this->getConsumer($amqpConnection, $amqpChannel);
     $callbackFunction = function () use($processFlag) {
         return $processFlag;
     };
     // Create a callback function with a return value set by the data provider.
     $consumer->setCallback($callbackFunction);
     // Create a default message
     $amqpMessage = new AMQPMessage('foo body');
     $amqpMessage->delivery_info['channel'] = $amqpChannel;
     $amqpMessage->delivery_info['delivery_tag'] = 0;
     $amqpChannel->expects($this->any())->method('basic_reject')->will($this->returnCallback(function ($delivery_tag, $requeue) use($expectedMethod, $expectedRequeue) {
         \PHPUnit_Framework_Assert::assertSame($expectedMethod, 'basic_reject');
         // Check if this function should be called.
         \PHPUnit_Framework_Assert::assertSame($requeue, $expectedRequeue);
         // Check if the message should be requeued.
     }));
     $amqpChannel->expects($this->any())->method('basic_ack')->will($this->returnCallback(function ($delivery_tag) use($expectedMethod) {
         \PHPUnit_Framework_Assert::assertSame($expectedMethod, 'basic_ack');
         // Check if this function should be called.
     }));
     $eventDispatcher = $this->getMockBuilder('Symfony\\Component\\EventDispatcher\\EventDispatcherInterface')->getMock();
     $consumer->setEventDispatcher($eventDispatcher);
     $eventDispatcher->expects($this->atLeastOnce())->method('dispatch')->withConsecutive(array(BeforeProcessingMessageEvent::NAME, new BeforeProcessingMessageEvent($consumer, $amqpMessage)), array(AfterProcessingMessageEvent::NAME, new AfterProcessingMessageEvent($consumer, $amqpMessage)))->willReturn(true);
     $consumer->processMessage($amqpMessage);
 }
Esempio n. 8
0
 /**
  * @When I run the tenanted command :command
  * @When I run the tenanted command :command with options :options
  * @param $command
  * @param $options
  */
 public function iRunTheCommand($command, $options = null)
 {
     $this->actualCommand = $command;
     $tenantedCommand = 'bin/tenant ' . $options . ' ' . PHP_BINARY . ' test/Vivait/TenantBundle/app/console --no-ansi ' . $command;
     $this->process = new Process($tenantedCommand);
     $this->process->run();
     PHPUnit_Framework_Assert::assertSame(0, $this->process->getExitCode(), 'Non zero return code received from command');
 }
Esempio n. 9
0
 /**
  * @covers Minifine\Minifier\Css\MatthiasMullie::__construct
  * @covers Minifine\Minifier\Css\MatthiasMullie::minify
  */
 public function testMinify()
 {
     $mock = $this->getMock('MatthiasMullie\\Minify\\CSS');
     $mock->expects($this->once())->method('add')->will($this->returnCallback(function ($data) {
         \PHPUnit_Framework_Assert::assertSame('passeddata', $data);
     }));
     $mock->expects($this->once())->method('minify')->willReturn('minified');
     $this->assertSame('minified', (new MatthiasMullie($mock))->minify('passeddata'));
 }
Esempio n. 10
0
 public function seeInData($key, $value = null)
 {
     $data = json_decode($this->lastRequest['body'], true);
     if ($value === null) {
         $this->assertNotEmpty($data[$key]);
     } else {
         \PHPUnit_Framework_Assert::assertSame($value, $data[$key]);
     }
 }
Esempio n. 11
0
 /**
  * @test
  */
 public function it_detects_proper_values_and_constants()
 {
     $enum = new FakeEnum();
     \PHPUnit_Framework_Assert::assertContains('SOME_KEY', $enum->keys());
     \PHPUnit_Framework_Assert::assertArrayHasKey('SOME_KEY', $enum->values());
     \PHPUnit_Framework_Assert::assertArrayNotHasKey('some-value', $enum->values());
     \PHPUnit_Framework_Assert::assertContains('some-value', $enum->values());
     \PHPUnit_Framework_Assert::assertSame('SOME_KEY', $enum->getConstantForValue('some-value'));
     \PHPUnit_Framework_Assert::assertTrue($enum->has('some-value'));
     \PHPUnit_Framework_Assert::assertFalse($enum->has('SOME-VALUE'));
 }
 protected function execute(Middleware $middleware, $command, $expectedNextCommand, $executeResult = null)
 {
     $nextWasCalled = false;
     $middleware->execute($command, function ($nextCommand) use($expectedNextCommand, &$nextWasCalled, $executeResult) {
         \PHPUnit_Framework_Assert::assertSame($expectedNextCommand, $nextCommand);
         $nextWasCalled = true;
         return $executeResult;
     });
     if (!$nextWasCalled) {
         throw new \LogicException('Middleware should have called the next callable.');
     }
 }
Esempio n. 13
0
 /** @test */
 public function anonymousCallback()
 {
     $context = $this->getMock('Superruzafa\\Rules\\Context');
     $flag = 0;
     $callback = function (Context $ctx) use(&$flag, $context) {
         $flag = 1;
         \PHPUnit_Framework_Assert::assertSame($ctx, $context);
         return 2;
     };
     $action = new RunCallback($callback);
     $this->assertEquals(2, $action->perform($context));
     $this->assertEquals(1, $flag);
 }
Esempio n. 14
0
 public function nextShouldExpectAndReturn($return, $request, $response)
 {
     $requestExpectation = Argument::that(function ($argument) use($request) {
         Assert::assertSame($request, $argument, 'Request passed to next does not match expectation');
         return true;
     });
     $responseExpectation = Argument::that(function ($argument) use($response) {
         Assert::assertSame($response, $argument, 'Response passed to next does not match expectation');
         return true;
     });
     $next = $this->prophesize(Next::class);
     $next->__invoke($requestExpectation, $responseExpectation)->willReturn($return);
     return $next->reveal();
 }
Esempio n. 15
0
 public function testSendTitledRequest()
 {
     $guzzleClient = $this->getGuzzleClientMock('{
         "title": "This Ain\'t Game of Thrones XXX",
         "year": "2014",
         "rated": "N/A",
         "released": "14 Apr 2014",
         "runtime": "N/A",
         "genre": "Adult",
         "director": "Axel Braun",
         "writer": "Axel Braun",
         "actors": "Richie Calhoun, Ryan Driller, Scarlett Fay, Alec Knight",
         "plot": "A XXX parody of the epic 2011 high fantasy TV series Game of Thrones.",
         "language": "English",
         "country": "USA",
         "awards": "1 nomination.",
         "poster": "N/A",
         "metascore": "N/A",
         "imdbRating": "3.5",
         "imdbVotes": "42",
         "imdbID": "tt3665102",
         "type": "movie",
         "response": "True"
     }');
     $client = new Client('API_KEY', $guzzleClient);
     $request = new RequestByTitle(new Title('This Ain\'t Game of Thrones XXX'));
     $response = $client->send($request);
     \PHPUnit_Framework_Assert::assertInstanceOf('ClearCode\\OMDB\\Response\\Response', $response);
     \PHPUnit_Framework_Assert::assertSame($response->getTitle(), 'This Ain\'t Game of Thrones XXX');
     \PHPUnit_Framework_Assert::assertSame($response->getYear(), '2014');
     \PHPUnit_Framework_Assert::assertSame($response->getRated(), 'N/A');
     \PHPUnit_Framework_Assert::assertSame($response->getReleased(), '14 Apr 2014');
     \PHPUnit_Framework_Assert::assertSame($response->getRuntime(), 'N/A');
     \PHPUnit_Framework_Assert::assertSame($response->getGenre(), 'Adult');
     \PHPUnit_Framework_Assert::assertSame($response->getDirector(), 'Axel Braun');
     \PHPUnit_Framework_Assert::assertSame($response->getWriter(), 'Axel Braun');
     \PHPUnit_Framework_Assert::assertSame($response->getActors(), 'Richie Calhoun, Ryan Driller, Scarlett Fay, Alec Knight');
     \PHPUnit_Framework_Assert::assertSame($response->getPlot(), 'A XXX parody of the epic 2011 high fantasy TV series Game of Thrones.');
     \PHPUnit_Framework_Assert::assertSame($response->getLanguage(), 'English');
     \PHPUnit_Framework_Assert::assertSame($response->getCountry(), 'USA');
     \PHPUnit_Framework_Assert::assertSame($response->getAwards(), '1 nomination.');
     \PHPUnit_Framework_Assert::assertSame($response->getPoster(), 'N/A');
     \PHPUnit_Framework_Assert::assertSame($response->getMetascore(), 'N/A');
     \PHPUnit_Framework_Assert::assertSame($response->getImdbRating(), '3.5');
     \PHPUnit_Framework_Assert::assertSame($response->getImdbVotes(), '42');
     \PHPUnit_Framework_Assert::assertSame($response->getImdbID(), 'tt3665102');
     \PHPUnit_Framework_Assert::assertSame($response->getType(), 'movie');
     \PHPUnit_Framework_Assert::assertSame($response->getResponse(), 'True');
 }
Esempio n. 16
0
 public function testSetterAndGetter()
 {
     $user = new UserDefault();
     PHPUnit::assertInstanceOf(DateTime::class, $user->getCreatedAt());
     PHPUnit::assertInstanceOf(DateTime::class, $user->getUpdatedAt());
     PHPUnit::assertNull($user->getDeletedAt());
     PHPUnit::assertSame('user', $user->getRole()->getName());
     $role = new UserRoleDefault('test');
     $user->setRole($role);
     PHPUnit::assertSame($role, $user->getRole());
     PHPUnit::assertFalse($user->isEnabled());
     $user->enable();
     PHPUnit::assertTrue($user->isEnabled());
     $user->disable();
     PHPUnit::assertFalse($user->isEnabled());
 }
 /**
  * Verifies the correct workflow of the ResponseListener
  *
  * @return void
  */
 public function testEventStatusLinkResponseListener()
 {
     $producerMock = $this->getMockBuilder('\\OldSound\\RabbitMqBundle\\RabbitMq\\ProducerInterface')->disableOriginalConstructor()->setMethods(['publish'])->getMockForAbstractClass();
     $producerMock->expects($this->once())->method('publish')->will($this->returnCallback(function ($message, $routingKey) {
         \PHPUnit_Framework_Assert::assertSame('{"event":"document.core.product.create","document":{"$ref":"graviton-api-test\\/core\\/product' . '"},"status":{"$ref":"http:\\/\\/graviton-test.lo\\/worker\\/123jkl890yui567mkl"}}', $message);
         \PHPUnit_Framework_Assert::assertSame('document.dude.config.create', $routingKey);
     }));
     $routerMock = $this->getMockBuilder('\\Symfony\\Component\\Routing\\RouterInterface')->disableOriginalConstructor()->setMethods(['generate'])->getMockForAbstractClass();
     $routerMock->expects($this->once())->method('generate')->willReturn('http://graviton-test.lo/worker/123jkl890yui567mkl');
     $requestMock = $this->getMockBuilder('\\Symfony\\Component\\HttpFoundation\\Request')->disableOriginalConstructor()->setMethods(['get'])->getMock();
     $requestMock->expects($this->atLeastOnce())->method('get')->will($this->returnCallback(function () {
         switch (func_get_arg(0)) {
             case '_route':
                 return 'graviton.core.rest.product.post';
                 break;
             case 'selfLink':
                 return 'graviton-api-test/core/product';
                 break;
         }
     }));
     $requestStackMock = $this->getMockBuilder('\\Symfony\\Component\\HttpFoundation\\RequestStack')->disableOriginalConstructor()->setMethods(['getCurrentRequest'])->getMock();
     $requestStackMock->expects($this->once())->method('getCurrentRequest')->willReturn($requestMock);
     $cursorMock = $this->getMockBuilder('\\Doctrine\\MongoDB\\CursorInterface')->disableOriginalConstructor()->getMockForAbstractClass();
     $cursorMock->expects($this->once())->method('toArray')->willReturn(['someWorkerId' => 'some content']);
     $queryMock = $this->getMockBuilder('\\Doctrine\\MongoDB\\Query\\Query')->disableOriginalConstructor()->getMock();
     $queryMock->expects($this->once())->method('execute')->willReturn($cursorMock);
     $queryBuilderMock = $this->getMockBuilder('\\Doctrine\\ODM\\MongoDB\\Query\\Builder')->disableOriginalConstructor()->getMock();
     $queryBuilderMock->expects($this->once())->method('select')->willReturnSelf();
     $queryBuilderMock->expects($this->once())->method('field')->willReturnSelf();
     $queryBuilderMock->expects($this->once())->method('equals')->willReturnSelf();
     $queryBuilderMock->expects($this->once())->method('getQuery')->willReturn($queryMock);
     $documentManagerMock = $this->getMockBuilder('\\Doctrine\\ODM\\MongoDB\\DocumentManager')->disableOriginalConstructor()->setMethods(['createQueryBuilder', 'persist', 'flush'])->getMock();
     $documentManagerMock->expects($this->once())->method('createQueryBuilder')->willReturn($queryBuilderMock);
     $documentManagerMock->expects($this->once())->method('persist')->with($this->isInstanceOf('\\GravitonDyn\\EventStatusBundle\\Document\\EventStatus'));
     $documentManagerMock->expects($this->once())->method('flush');
     $queueEventMock = $this->getMockBuilder('\\Graviton\\RabbitMqBundle\\Document\\QueueEvent')->setMethods(['getEvent'])->getMock();
     $queueEventMock->expects($this->exactly(5))->method('getEvent')->willReturn('document.dude.config.create');
     $filterResponseEventMock = $this->getMockBuilder('\\Symfony\\Component\\HttpKernel\\Event\\FilterResponseEvent')->disableOriginalConstructor()->setMethods(['isMasterRequest', 'getResponse'])->getMock();
     $filterResponseEventMock->expects($this->once())->method('isMasterRequest')->willReturn(true);
     $response = new Response();
     $filterResponseEventMock->expects($this->once())->method('getResponse')->willReturn($response);
     $listener = new EventStatusLinkResponseListener($producerMock, $routerMock, $requestStackMock, $documentManagerMock, $queueEventMock, ['Testing' => ['baseRoute' => 'graviton.core.rest.product', 'events' => ['post' => 'document.core.product.create', 'put' => 'document.core.product.update', 'delete' => 'document.core.product.delete']]], '\\GravitonDyn\\EventWorkerBundle\\Document\\EventWorker', '\\GravitonDyn\\EventStatusBundle\\Document\\EventStatus', '\\GravitonDyn\\EventStatusBundle\\Document\\EventStatusStatus', 'gravitondyn.eventstatus.rest.eventstatus.get');
     $listener->onKernelResponse($filterResponseEventMock);
     $this->assertEquals('<http://graviton-test.lo/worker/123jkl890yui567mkl>; rel="eventStatus"', $response->headers->get('Link'));
 }
Esempio n. 18
0
 /**
  * @covers Pushy\Router\FrontController::__construct
  * @covers Pushy\Router\FrontController::dispatch
  * @covers Pushy\Router\FrontController::setParameters
  */
 public function testDispatchWithParams()
 {
     $route = $this->getMock('\\Pushy\\Router\\AccessPoint');
     $route->expects($this->any())->method('getCallback')->will($this->returnValue(function ($request) {
         return 'foo';
     }));
     $route->expects($this->any())->method('getPath')->will($this->returnValue('/(foo)/'));
     $router = $this->getMock('\\Pushy\\Router\\Routable');
     $router->expects($this->any())->method('getRouteByRequest')->will($this->returnValue($route));
     $request = $this->getMock('\\Pushy\\Network\\Http\\RequestData');
     $request->expects($this->any())->method('setParameters')->will($this->returnCallback(function ($params) {
         \PHPUnit_Framework_Assert::assertSame(['foo'], $params);
     }));
     $request->expects($this->any())->method('getPath')->will($this->returnValue('/foo'));
     $response = $this->getMock('\\Pushy\\Network\\Http\\ResponseData');
     $response->expects($this->any())->method('setBody')->will($this->returnCallback(function ($body) {
         \PHPUnit_Framework_Assert::assertSame('foo', $body);
     }));
     $frontcontroller = new FrontController($request, $response, $router);
     $this->assertNull($frontcontroller->dispatch());
 }
Esempio n. 19
0
 public function testExhangeBind()
 {
     $ch = $this->prepareAMQPChannel('channel_id');
     $con = $this->prepareAMQPConnection();
     $source = 'example_source';
     $destination = 'example_destination';
     $key = 'example_key';
     $ch->expects($this->once())->method('exchange_bind')->will($this->returnCallback(function ($d, $s, $k, $n, $a) use($destination, $source, $key) {
         \PHPUnit_Framework_Assert::assertSame($destination, $d);
         \PHPUnit_Framework_Assert::assertSame($source, $s);
         \PHPUnit_Framework_Assert::assertSame($key, $k);
         \PHPUnit_Framework_Assert::assertFalse($n);
         \PHPUnit_Framework_Assert::assertNull($a);
     }));
     $binding = $this->getBinding($con, $ch);
     $binding->setExchange($source);
     $binding->setDestination($destination);
     $binding->setRoutingKey($key);
     $binding->setDestinationIsExchange(true);
     $binding->setupFabric();
 }
Esempio n. 20
0
 private function validateMockApiResponse()
 {
     /** @var MockApiResponse $response */
     $response = $this->response;
     Assert::assertSame($this->method, $response->getMethod());
     Assert::assertSame($this->path, $response->getPath());
     Assert::assertSame($this->queryParams, $response->getQueryParams());
     Assert::assertSame($this->content, $response->getContent());
     Assert::assertSame($this->user, $response->getUser());
     foreach ($this->headers as $key => $value) {
         Assert::assertSame($value, $response->getHeaders()[$key]);
     }
     foreach ($this->files as $key => $value) {
         Assert::assertSame($this->files[$key]['name'], $response->getFiles()[$key]['name']);
     }
 }
 protected function checkSingleEvent($expected, Event $event, &$eventsByInternalId, &$unmatchedParentEvents)
 {
     /* @var $event NodeEvent */
     $rowId = null;
     foreach ($expected as $rowName => $rowValue) {
         switch ($rowName) {
             case 'ID':
                 if ($rowValue === '') {
                     break;
                 }
                 $rowId = $rowValue;
                 break;
             case 'Parent Event':
                 if ($rowValue === '') {
                     break;
                 }
                 if (isset($eventsByInternalId[$rowValue])) {
                     Assert::assertSame($eventsByInternalId[$rowValue], $event->getParentEvent(), 'Parent event does not match. (1)');
                 } elseif (isset($unmatchedParentEvents[$rowValue]) && $unmatchedParentEvents[$rowValue] !== $event->getParentEvent()) {
                     Assert::fail(sprintf('Parent event "%s" does not match another parent event with the same identifier.', $rowValue));
                 } else {
                     $unmatchedParentEvents[$rowValue] = $event->getParentEvent();
                 }
                 break;
             case 'Event Type':
                 Assert::assertEquals($rowValue, $event->getEventType(), 'Event Type does not match. Expected: ' . $rowValue . '. Actual: ' . $event->getEventType());
                 break;
             case 'Node Identifier':
                 if ($rowValue === '') {
                     break;
                 }
                 Assert::assertEquals($rowValue, $event->getNodeIdentifier(), 'Node Identifier does not match.');
                 break;
             case 'Document Node Identifier':
                 Assert::assertEquals($rowValue, $event->getDocumentNodeIdentifier(), 'Document Node Identifier does not match.');
                 break;
             case 'Workspace':
                 Assert::assertEquals($rowValue, $event->getWorkspaceName(), 'Workspace does not match.');
                 break;
             case 'Explanation':
                 break;
             default:
                 throw new \Exception('Row Name ' . $rowName . ' not supported.');
         }
     }
     if ($rowId !== null) {
         $eventsByInternalId[$rowId] = $event;
         if (isset($unmatchedParentEvents[$rowId])) {
             Assert::assertSame($eventsByInternalId[$rowId], $event, 'Parent event does not match. (2)');
             unset($unmatchedParentEvents[$rowId]);
         }
     }
 }
Esempio n. 22
0
/**
 * Asserts that two variables have the same type and value.
 * Used on objects, it asserts that two variables reference
 * the same object.
 *
 * @param  mixed  $expected
 * @param  mixed  $actual
 * @param  string $message
 */
function assertSame($expected, $actual, $message = '')
{
    return PHPUnit_Framework_Assert::assertSame($expected, $actual, $message);
}
 public function testArrayAccess()
 {
     $this->resolver->setDefault('default1', 0);
     $this->resolver->setDefault('default2', 1);
     $this->resolver->setRequired('required');
     $this->resolver->setDefined('defined');
     $this->resolver->setDefault('lazy1', function (Options $options) {
         return 'lazy';
     });
     $this->resolver->setDefault('lazy2', function (Options $options) {
         \PHPUnit_Framework_Assert::assertTrue(isset($options['default1']));
         \PHPUnit_Framework_Assert::assertTrue(isset($options['default2']));
         \PHPUnit_Framework_Assert::assertTrue(isset($options['required']));
         \PHPUnit_Framework_Assert::assertTrue(isset($options['lazy1']));
         \PHPUnit_Framework_Assert::assertTrue(isset($options['lazy2']));
         \PHPUnit_Framework_Assert::assertFalse(isset($options['defined']));
         \PHPUnit_Framework_Assert::assertSame(0, $options['default1']);
         \PHPUnit_Framework_Assert::assertSame(42, $options['default2']);
         \PHPUnit_Framework_Assert::assertSame('value', $options['required']);
         \PHPUnit_Framework_Assert::assertSame('lazy', $options['lazy1']);
         // Obviously $options['lazy'] and $options['defined'] cannot be
         // accessed
     });
     $this->resolver->resolve(array('default2' => 42, 'required' => 'value'));
 }
 public function _verify($message = null)
 {
     \PHPUnit_Framework_Assert::assertSame($this->expected, $this->actual, $message);
 }
Esempio n. 25
0
 /**
  * @Then field :getProperty should be :propertyValue
  *
  * @param $getProperty
  * @param $propertyValue
  */
 public function fieldShouldBe($getProperty, $propertyValue)
 {
     \PHPUnit_Framework_Assert::assertSame($this->target->{$getProperty}(), $propertyValue);
 }
Esempio n. 26
0
 public function testBadExtensionSnippets()
 {
     $app = $this->getApp();
     $logger = $this->getMock('\\Monolog\\Logger', ['critical'], ['testlogger']);
     $logger->expects($this->atLeastOnce())->method('critical')->will($this->returnCallback(function ($message) {
         \PHPUnit_Framework_Assert::assertSame('Snippet loading failed for Bolt\\Tests\\Extensions\\Mock\\BadExtensionSnippets with callable a:2:{i:0;O:47:"Bolt\\Tests\\Extensions\\Mock\\BadExtensionSnippets":0:{}i:1;s:18:"badSnippetCallBack";}', $message);
     }));
     $app['asset.queue.snippet'] = new \Bolt\Asset\Snippet\Queue($app['asset.injector'], $app['cache'], $app['config'], $app['resources'], $app['request_stack'], $logger);
     $app['extensions']->register(new Mock\BadExtensionSnippets($app));
     $html = $app['asset.queue.snippet']->process($this->template);
     $this->assertEquals($this->html($this->template), $this->html($html));
 }
Esempio n. 27
0
 /**
  * @covers CodeCollab\Router\Router::__construct
  * @covers CodeCollab\Router\Router::addRoute
  * @covers CodeCollab\Router\Router::get
  * @covers CodeCollab\Router\Router::buildCache
  * @covers CodeCollab\Router\Router::getDispatcher
  */
 public function testGetDispatcherExistingFileDoReload()
 {
     $routeCollector = $this->createMock(RouteCollector::class);
     $routeCollector->method('getData')->willReturn(['foo' => 'bar']);
     $router = new Router($routeCollector, function ($data) {
         \PHPUnit_Framework_Assert::assertSame(['foo' => 'bar'], $data);
         return $this->createMock(Dispatcher::class);
     }, TEST_DATA_DIR . '/cache/routes.php', true);
     $this->assertFalse(file_exists(TEST_DATA_DIR . '/cache/routes.php'));
     copy(TEST_DATA_DIR . '/routes.php', TEST_DATA_DIR . '/cache/routes.php');
     $this->assertTrue(file_exists(TEST_DATA_DIR . '/cache/routes.php'));
     $this->assertInstanceOf(Dispatcher::class, $router->get('/', [])->getDispatcher());
     $this->assertTrue(file_exists(TEST_DATA_DIR . '/cache/routes.php'));
     $routes = (require TEST_DATA_DIR . '/cache/routes.php');
     $this->assertSame(['foo' => 'bar'], $routes);
 }
 /**
  * @param PyStringNode $message
  *
  * @throws \Exception
  *
  * @Then /^command should throw an exception$/
  * @Then /^command should throw following exception:?$/
  */
 public function commandShouldThrowException(PyStringNode $message = null)
 {
     if (!$this->exception instanceof \Exception) {
         throw new \Exception('Command does not throw any exception', 0, $this->exception);
     }
     if (null !== $message) {
         try {
             \PHPUnit_Framework_Assert::assertSame($message->getRaw(), $this->exception->getMessage());
         } catch (\PHPUnit_Framework_ExpectationFailedException $e) {
             throw new \Exception(sprintf('Command exception message "%s" does not match expected "%s"', $this->exception->getMessage(), $message->getRaw()), 0, $e);
         }
     }
 }
Esempio n. 29
0
 /**
  * @Then the certificate for the domain :domain should contains:
  */
 public function theCertificateForTheDomainShouldContains($domain, PyStringNode $content)
 {
     $certFile = $this->storageDir . '/domains/' . $domain . '/cert.pem';
     $parser = new CertificateParser();
     $certificateMetadata = $parser->parse(file_get_contents($certFile));
     $accessor = new PropertyAccessor();
     $yaml = new Yaml();
     $expected = $yaml->parse($content->getRaw());
     foreach ($expected as $key => $value) {
         PHPUnit_Framework_Assert::assertTrue($accessor->isReadable($certificateMetadata, $key));
         $formattedValue = $accessor->getValue($certificateMetadata, $key);
         if (is_array($value) && is_array($formattedValue)) {
             sort($value);
             sort($formattedValue);
         }
         PHPUnit_Framework_Assert::assertSame($value, $formattedValue);
     }
 }
Esempio n. 30
0
 public function toHaveLength($length)
 {
     if ($this->negate) {
         a::assertNotSame($length, strlen($this->actual));
     } else {
         a::assertSame($length, strlen($this->actual));
     }
 }