assertInstanceOf() public static méthode

Asserts that a variable is of a given type.
public static assertInstanceOf ( string $expected, mixed $actual, string $message = '' )
$expected string
$actual mixed
$message string
 /**
  * @Given /^There are activity for questions$/
  */
 public function thereAreActivityForQuestions(TableNode $table)
 {
     /* @var $em EntityManager */
     $em = $this->getEm();
     /* @var $activityService \Civix\CoreBundle\Service\ActivityUpdate */
     $activityService = $this->getMainContext()->getContainer()->get('civix_core.activity_update');
     $hash = $table->getHash();
     $diffSec = 0;
     foreach ($hash as $row) {
         /* @var $question Question */
         $diffSec++;
         $question = $em->getRepository(Question::class)->findOneBySubject($row['question']);
         $activity = $activityService->publishQuestionToActivity($question);
         Assert::assertInstanceOf(Activity::class, $activity);
         $activity->getSentAt()->sub(new \DateInterval('PT' . (count($hash) - $diffSec) . 'S'));
         $activity->setSentAt(clone $activity->getSentAt());
         $em->flush($activity);
         if (!empty($row['expired_interval_direction'])) {
             $expired = new \DateTime();
             $expired->{$row}['expired_interval_direction'](new \DateInterval($row['expired_interval_value']));
             $activity->setExpireAt($expired);
             $em->flush($activity);
         }
     }
     $result = $em->getRepository(QuestionActivity::class)->findAll();
     Assert::assertTrue(count($result) >= count($hash));
 }
 public function assertLockDiscoveryPropertyCorrect(ezcWebdavMemoryBackend $backend)
 {
     $prop = $backend->getProperty('/collection/newcollection', 'lockdiscovery');
     PHPUnit_Framework_Assert::assertNotNull($prop, 'Lock discovery property not set.');
     PHPUnit_Framework_Assert::assertInstanceOf('ezcWebdavLockDiscoveryProperty', $prop, 'Lock discovery property has incorrect type.');
     PHPUnit_Framework_Assert::assertEquals(1, count($prop->activeLock), 'Number of activeLock elements incorrect.');
     PHPUnit_Framework_Assert::assertEquals(new ezcWebdavPotentialUriContent('http://example.com/some/user', true), $prop->activeLock[0]->owner, 'Lock owner not correct.');
 }
 public function testProcess()
 {
     if (!class_exists(TransactionMiddleware::class)) {
         $this->markTestSkipped('"league/tactician-doctrine" is not installed');
     }
     $this->container->shouldReceive('hasParameter')->with('doctrine.entity_managers')->once()->andReturn(true);
     $this->container->shouldReceive('getParameter')->with('doctrine.entity_managers')->once()->andReturn(['default' => 'doctrine.orm.default_entity_manager', 'second' => 'doctrine.orm.second_entity_manager']);
     $this->container->shouldReceive('getParameter')->with('doctrine.default_entity_manager')->once()->andReturn('default');
     $this->container->shouldReceive('setDefinition')->andReturnUsing(function ($name, Definition $def) {
         \PHPUnit_Framework_Assert::assertEquals('tactician.middleware.doctrine.default', $name);
         \PHPUnit_Framework_Assert::assertEquals(TransactionMiddleware::class, $def->getClass());
         \PHPUnit_Framework_Assert::assertCount(1, $def->getArguments());
         \PHPUnit_Framework_Assert::assertInstanceOf(Reference::class, $def->getArgument(0));
         \PHPUnit_Framework_Assert::assertEquals('doctrine.orm.default_entity_manager', (string) $def->getArgument(0));
     })->once();
     $this->container->shouldReceive('setDefinition')->andReturnUsing(function ($name, Definition $def) {
         \PHPUnit_Framework_Assert::assertEquals('tactician.middleware.doctrine.second', $name);
         \PHPUnit_Framework_Assert::assertEquals(TransactionMiddleware::class, $def->getClass());
         \PHPUnit_Framework_Assert::assertCount(1, $def->getArguments());
         \PHPUnit_Framework_Assert::assertInstanceOf(Reference::class, $def->getArgument(0));
         \PHPUnit_Framework_Assert::assertEquals('doctrine.orm.second_entity_manager', (string) $def->getArgument(0));
     })->once();
     $this->container->shouldReceive('setDefinition')->with('tactician.middleware.doctrine.second')->once();
     $this->container->shouldReceive('setAlias')->once()->with('tactician.middleware.doctrine', 'tactician.middleware.doctrine.default');
     $this->compiler->process($this->container);
 }
Exemple #4
0
 /**
  * @Given /^the Search Hits are Content objects$/
  */
 public function theSearchHitsAreContentObjects()
 {
     /** @var SearchHit[] $searchHits */
     $searchHits = $this->getResponseObject()->result->searchHits;
     foreach ($searchHits as $searchHit) {
         Assertion::assertInstanceOf('eZ\\Publish\\API\\Repository\\Values\\Content\\Content', $searchHit->valueObject);
     }
 }
 /**
  * @test
  */
 public function shouldCreateAnUser()
 {
     $user = $this->mockUser();
     $userToken = $this->mockUserToken();
     $factory = new UserSessionFactoryDefault();
     $userSession = $factory->create($user, $userToken);
     \PHPUnit_Framework_Assert::assertInstanceOf(UserSessionDefault::class, $userSession);
 }
 /**
  * @test
  */
 public function shouldCreateAnUser()
 {
     $container = $this->mockDependencyInjectionContainer();
     $serializer = $this->mockSerializer();
     $factory = new UserFactoryDefault($container, $serializer);
     $user = $factory->create();
     \PHPUnit_Framework_Assert::assertInstanceOf(User::class, $user);
 }
Exemple #7
0
 public function testSendIdentitiedRequest()
 {
     $guzzleClient = $this->getGuzzleClientMock('{}');
     $client = new Client('API_KEY', $guzzleClient);
     $request = new RequestById(new Id('tt3665102'));
     $response = $client->send($request);
     \PHPUnit_Framework_Assert::assertInstanceOf('ClearCode\\OMDB\\Response\\Response', $response);
 }
 public function assertLockDiscoveryPropertyNowhere(ezcWebdavMemoryBackend $backend)
 {
     $prop = $backend->getProperty('/collection', 'lockdiscovery');
     PHPUnit_Framework_Assert::assertInstanceOf('ezcWebdavLockDiscoveryProperty', $prop, 'Property has incorrect type.');
     PHPUnit_Framework_Assert::assertEquals(0, count($prop->activeLock), 'Active lock element not removed correctly.');
     $prop = $backend->getProperty('/collection/resource.html', 'lockdiscovery');
     PHPUnit_Framework_Assert::assertNull($prop);
 }
 public function assertSourceStillThere(ezcWebdavMemoryBackend $backend)
 {
     PHPUnit_Framework_Assert::assertTrue($backend->nodeExists('/collection/resource.html'));
     $prop = $backend->getProperty('/collection/resource.html', 'lockdiscovery');
     PHPUnit_Framework_Assert::assertNotNull($prop, 'Lock discovery property removed from source.');
     PHPUnit_Framework_Assert::assertInstanceOf('ezcWebdavLockDiscoveryProperty', $prop);
     PHPUnit_Framework_Assert::assertEquals(1, count($prop->activeLock), 'Active lock element removed from source.');
     PHPUnit_Framework_Assert::assertEquals('opaquelocktoken:1234', $prop->activeLock[0]->token->__toString(), 'Active lock token on destination parent incorrect.');
 }
 /**
  * Checks the integrity of operations links.
  *
  * @param mixed[] $operations_links
  */
 protected function assertOperationsLinks(array $operations_links)
 {
     foreach ($operations_links as $link) {
         \PHPUnit_Framework_Assert::assertArrayHasKey('title', $link);
         \PHPUnit_Framework_Assert::assertNotEmpty($link['title']);
         \PHPUnit_Framework_Assert::assertArrayHasKey('url', $link);
         \PHPUnit_Framework_Assert::assertInstanceOf(Url::class, $link['url']);
     }
 }
 public function assertDestinationCorrect(ezcWebdavMemoryBackend $backend)
 {
     PHPUnit_Framework_Assert::assertTrue($backend->nodeExists('/other_collection/moved_resource.html'));
     $prop = $backend->getProperty('/other_collection/moved_resource.html', 'lockdiscovery');
     PHPUnit_Framework_Assert::assertNotNull($prop, 'Lock discovery property not available on destination.');
     PHPUnit_Framework_Assert::assertInstanceOf('ezcWebdavLockDiscoveryProperty', $prop);
     PHPUnit_Framework_Assert::assertEquals(1, count($prop->activeLock), 'Active lock element not available on destination.');
     PHPUnit_Framework_Assert::assertEquals('opaquelocktoken:5678', $prop->activeLock[0]->token->__toString(), 'Active lock token on destination incorrect.');
 }
Exemple #12
0
 /**
  * @Given /^response contains only the user with the email "([^"]*)"$/
  */
 public function responseContainsOnlyUsersWithTheEmail($email)
 {
     $userList = $this->getResponseObject();
     Assertion::assertGreaterThan(0, count($userList), 'UserList was expected to contain one user only');
     foreach ($userList as $user) {
         Assertion::assertInstanceOf('eZ\\Publish\\API\\Repository\\Values\\User\\User', $user, 'Non User found in the response');
         Assertion::assertEquals($email, $user->email, "UserList was expected to contain only users with email '{$email}'");
     }
 }
 public function assertRedirect($uri, $str = null)
 {
     PHPUnit::assertInstanceOf('Illuminate\\Http\\RedirectResponse', $this->response);
     if ($str) {
         PHPUnit::assertEquals($this->app['url']->to($uri), $this->response->headers->get('Location'), 'Caller: ' . $this->getCaller() . ' ' . $str);
     } else {
         PHPUnit::assertEquals($this->app['url']->to($uri), $this->response->headers->get('Location'));
     }
 }
 /**
  * @test
  */
 public function it_returns_new_command_with_uuid_instance()
 {
     $argumentProcessor = new ArgumentsProcessor([new UuidConverter()]);
     $commandReflection = CommandReflection::fromClass(DummyCommandWithUuid::class);
     $commandParameters = ['lorem ipsum', '1a67b1de-e3cb-471e-90d3-005341a29b3d'];
     $command = $commandReflection->createCommand($commandParameters, $argumentProcessor);
     \PHPUnit_Framework_Assert::assertInstanceOf(DummyCommandWithUuid::class, $command);
     \PHPUnit_Framework_Assert::assertEquals('lorem ipsum', $command->argument1);
     \PHPUnit_Framework_Assert::assertTrue(Uuid::fromString('1a67b1de-e3cb-471e-90d3-005341a29b3d')->equals($command->argument2));
 }
Exemple #15
0
 public function tryList(FunctionalTester $I)
 {
     $I->wantTo("Check module list output");
     $this->routeMatch->setParam('action', 'show');
     $result = $this->controller->dispatch(new ConsoleRequest(array(0 => 'public/index.php', 1 => 'modules', 2 => 'list')));
     /** @var Zend\Http\PhpEnvironment\Response $response */
     $response = $this->controller->getResponse();
     \PHPUnit_Framework_Assert::assertEquals(200, $response->getStatusCode());
     \PHPUnit_Framework_Assert::assertEquals('', $result);
     \PHPUnit_Framework_Assert::assertInstanceOf('ComposerLockParser\\PackagesCollection', $this->viewModel->getPackages());
     \PHPUnit_Framework_Assert::assertGreaterThan(0, $this->viewModel->getPackages()->count());
     \PHPUnit_Framework_Assert::assertInstanceOf('ComposerLockParser\\Package', $this->viewModel->getPackages()->getByName('t4web/modules'));
 }
 /**
  * @param string|string[] $expected
  * @param Exception $ex
  */
 public function assertUsageException($expected, Exception $ex)
 {
     Assert::assertInstanceOf('UsageException', $ex);
     /** @var UsageException $ex */
     if (is_string($expected)) {
         $expected = array('code' => $expected);
     }
     if (isset($expected['code'])) {
         Assert::assertEquals($expected['code'], $ex->getCodeString());
     }
     if (isset($expected['message'])) {
         Assert::assertContains($expected['message'], $ex->getMessage());
     }
 }
Exemple #17
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());
 }
 public function testMessagesTypes()
 {
     $path = '/test/path';
     $mockAdapter = new MockAdapter();
     // Adds mock basic OK response
     $mockAdapter->addResponseBy();
     // Add mock adapter
     $this->_client->setAdapter($mockAdapter);
     // Send request
     $this->_client->get($path);
     // Gets message objects
     $request = $this->_client->getRequest();
     $response = $this->_client->getResponse();
     // Tests request and response are objects
     \PHPUnit_Framework_Assert::assertInstanceOf(self::CLIENT_NAMESPACE . 'Request', $request);
     \PHPUnit_Framework_Assert::assertInstanceOf(self::CLIENT_NAMESPACE . 'Response', $response);
 }
 /**
  * @test
  */
 public function it_should_handle_with_response()
 {
     $wholeMessageLength = 0 + \Madkom\EventStore\Client\Domain\Socket\Message\MessageConfiguration::INT_32_LENGTH + \Madkom\EventStore\Client\Domain\Socket\Message\MessageConfiguration::HEADER_LENGTH;
     $buffer = new \TrafficCophp\ByteBuffer\Buffer($wholeMessageLength);
     $buffer->writeInt32LE(18, 0);
     $buffer->writeInt8(\Madkom\EventStore\Client\Domain\Socket\Message\MessageType::PING, \Madkom\EventStore\Client\Domain\Socket\Message\MessageConfiguration::MESSAGE_TYPE_OFFSET);
     $buffer->writeInt8(\Madkom\EventStore\Client\Domain\Socket\Message\MessageConfiguration::FLAGS_NONE, \Madkom\EventStore\Client\Domain\Socket\Message\MessageConfiguration::FLAG_OFFSET);
     $buffer->write(hex2bin('12350000000000000000000000000000'), \Madkom\EventStore\Client\Domain\Socket\Message\MessageConfiguration::CORRELATION_ID_OFFSET);
     $messageTypeChanged = $this->internalProphet->prophesize('Madkom\\EventStore\\Client\\Domain\\Socket\\Message\\MessageType');
     $messageTypeChanged->getType()->willReturn(\Madkom\EventStore\Client\Domain\Socket\Message\MessageType::HEARTBEAT_REQUEST);
     $messageTypeChanged = $messageTypeChanged->reveal();
     $this->socketMessage->getMessageType()->willReturn($messageTypeChanged);
     $this->socketMessage->getCorrelationID()->willReturn('some');
     $this->messageDecomposer->decomposeMessage((string) $buffer)->willReturn($this->socketMessage->reveal());
     $this->messageComposer->compose(\Prophecy\Argument::type('Madkom\\EventStore\\Client\\Domain\\Socket\\Message\\SocketMessage'))->willReturn('someBinary');
     $this->stream->write('someBinary')->shouldBeCalledTimes(1);
     $this->stream->reveal();
     PHPUnit_Framework_Assert::assertInstanceOf('Madkom\\EventStore\\Client\\Domain\\Socket\\Message\\SocketMessage', $this->streamHandler->handle((string) $buffer));
 }
 public function testBitstampDriver()
 {
     $client = $this->getQuoteClient();
     $quotes = $client->getQuotes('bitstamp', [['base' => 'USD', 'target' => 'BTC']]);
     if (getenv('ECHO_QUOTES')) {
         echo "\$quotes:\n" . json_encode($quotes, 192) . "\n";
     }
     PHPUnit::assertInstanceOf('Tokenly\\CryptoQuoteClient\\Quote', $quotes[0]);
     PHPUnit::assertGreaterThan(100, $quotes[0]['bid']);
     PHPUnit::assertGreaterThan(100, $quotes[0]['ask']);
     PHPUnit::assertGreaterThan(100, $quotes[0]['last']);
     $quote = $client->getQuote('bitstamp', 'USD', 'BTC');
     if (getenv('ECHO_QUOTES')) {
         echo "\$quote:\n" . json_encode($quote, 192) . "\n";
     }
     PHPUnit::assertGreaterThan(100, $quote['bid']);
     PHPUnit::assertGreaterThan(100, $quote['ask']);
     PHPUnit::assertGreaterThan(100, $quote['last']);
 }
 /**
  * Assert whether the client was redirected to a given URI.
  *
  * @param  string  $uri
  * @param  array   $with
  * @return $this
  */
 public function assertRedirectedTo($uri, $with = [])
 {
     PHPUnit::assertInstanceOf('Illuminate\\Http\\RedirectResponse', $this->response);
     PHPUnit::assertEquals($this->app['url']->to($uri), $this->response->headers->get('Location'));
     $this->assertSessionHasAll($with);
     return $this;
 }
Exemple #22
0
 /**
  * Check if one of the given nodes has the given text.
  *
  * @param NodeElement[] $elements
  * @param string        $text
  *
  * @throws \Exception
  */
 private function assertANodeElementContainsText(array $elements, $text)
 {
     foreach ($elements as $element) {
         PHPUnit::assertInstanceOf(NodeElement::class, $element, sprintf('Expected a %s element', NodeElement::class));
         try {
             $this->assertNodeElementContainsText($element, $text);
             return;
         } catch (\PHPUnit_Framework_AssertionFailedError $exception) {
             // Does nothing
         }
     }
     // The given text has not been found, throw an error
     throw new \Exception(sprintf('No element contains the text "%s".', $text));
 }
Exemple #23
0
 /**
  * @When /^I get a user and receive a retrofit response$/
  */
 public function iGetAUserAndReceiveARetrofitResponse()
 {
     $this->setExpectations('GET', '/api/basic/user');
     $client = $this->getClient();
     /** @var Response $response */
     $response = $client->getUserReturnRetrofitResponse();
     Assert::assertInstanceOf(Response::class, $response);
     $this->response = $response->body();
 }
Exemple #24
0
/**
 * Asserts that a variable is of a given type.
 *
 * @param string $expected
 * @param mixed  $actual
 * @param string $message
 * @since Method available since Release 3.5.0
 */
function assertInstanceOf($expected, $actual, $message = '')
{
    return PHPUnit_Framework_Assert::assertInstanceOf($expected, $actual, $message);
}
    /**
     * @throws ParseFailureException
     */
    function it_can_parse_Literal_directive()
    {
        /** @var RootNode $root */
        $root = $this->parse(<<<EOF
internal "txt";
EOF
);
        $root->shouldReturnAnInstanceOf(RootNode::class);
        $directives = $root->search(function (Node $node) {
            return $node;
        })->getWrappedObject();
        /** @var Directive $directive */
        foreach ($directives as $directive) {
            break;
        }
        Assert::assertEquals($directive->getName(), 'internal');
        Assert::assertInstanceOf(Traversable::class, $directive->getParams());
        /** @var Param $param */
        foreach ($directive->getParams() as $param) {
            Assert::assertInstanceOf(Literal::class, $param);
        }
    }
 public function testDownloadCallback()
 {
     // Upload a file.
     $upload_file_path = Helper\get_png();
     $upload_test = new Test();
     $upload_test->server('upload_response', 'POST', array('image' => '@' . $upload_file_path));
     $uploaded_file_path = $upload_test->curl->response->file_path;
     // Download the file.
     $download_callback_called = false;
     $multi_curl = new MultiCurl();
     $multi_curl->setHeader('X-DEBUG-TEST', 'download_response');
     $multi_curl->addDownload(Test::TEST_URL . '?' . http_build_query(array('file_path' => $uploaded_file_path)), function ($instance, $fh) use(&$download_callback_called) {
         PHPUnit_Framework_Assert::assertFalse($download_callback_called);
         PHPUnit_Framework_Assert::assertInstanceOf('Curl\\Curl', $instance);
         PHPUnit_Framework_Assert::assertTrue(is_resource($fh));
         PHPUnit_Framework_Assert::assertEquals('stream', get_resource_type($fh));
         PHPUnit_Framework_Assert::assertGreaterThan(0, strlen(stream_get_contents($fh)));
         PHPUnit_Framework_Assert::assertEquals(0, strlen(stream_get_contents($fh)));
         PHPUnit_Framework_Assert::assertTrue(fclose($fh));
         $download_callback_called = true;
     });
     $multi_curl->start();
     $this->assertTrue($download_callback_called);
     // Remove server file.
     $this->assertEquals('true', $upload_test->server('upload_cleanup', 'POST', array('file_path' => $uploaded_file_path)));
     unlink($upload_file_path);
     $this->assertFalse(file_exists($upload_file_path));
     $this->assertFalse(file_exists($uploaded_file_path));
 }
 public function testErrorCallback()
 {
     $before_send_called = false;
     $success_called = false;
     $error_called = false;
     $complete_called = false;
     $test = new Test();
     $curl = $test->curl;
     $curl->setHeader('X-DEBUG-TEST', 'get');
     $curl->setOpt(CURLOPT_CONNECTTIMEOUT_MS, 2000);
     $curl->beforeSend(function ($instance) use(&$before_send_called, &$success_called, &$error_called, &$complete_called) {
         PHPUnit_Framework_Assert::assertInstanceOf('Curl\\Curl', $instance);
         PHPUnit_Framework_Assert::assertFalse($before_send_called);
         PHPUnit_Framework_Assert::assertFalse($success_called);
         PHPUnit_Framework_Assert::assertFalse($error_called);
         PHPUnit_Framework_Assert::assertFalse($complete_called);
         $before_send_called = true;
     });
     $curl->success(function ($instance) use(&$before_send_called, &$success_called, &$error_called, &$complete_called) {
         $success_called = true;
     });
     $curl->error(function ($instance) use(&$before_send_called, &$success_called, &$error_called, &$complete_called) {
         PHPUnit_Framework_Assert::assertInstanceOf('Curl\\Curl', $instance);
         PHPUnit_Framework_Assert::assertTrue($before_send_called);
         PHPUnit_Framework_Assert::assertFalse($success_called);
         PHPUnit_Framework_Assert::assertFalse($error_called);
         PHPUnit_Framework_Assert::assertFalse($complete_called);
         $error_called = true;
     });
     $curl->complete(function ($instance) use(&$before_send_called, &$success_called, &$error_called, &$complete_called) {
         PHPUnit_Framework_Assert::assertInstanceOf('Curl\\Curl', $instance);
         PHPUnit_Framework_Assert::assertTrue($before_send_called);
         PHPUnit_Framework_Assert::assertFalse($success_called);
         PHPUnit_Framework_Assert::assertTrue($error_called);
         PHPUnit_Framework_Assert::assertFalse($complete_called);
         $complete_called = true;
     });
     $curl->get(Test::ERROR_URL);
     $this->assertTrue($before_send_called);
     $this->assertFalse($success_called);
     $this->assertTrue($error_called);
     $this->assertTrue($complete_called);
 }
 /**
  * @Then /the (.+) user should be registered library user/
  */
 public function theUserShouldBeRegisteredLibraryUser($email)
 {
     \PHPUnit_Framework_Assert::assertInstanceOf(User::class, $this->userRepository()->get($email));
 }
Exemple #29
0
 /**
  * Checks that the property is a passed type.
  * Either 'int', 'bool', 'string', 'array', 'float', 'null', 'resource', 'scalar' can be passed for simple types.
  * Otherwise the parameter must be a class and the property must be an instance of that class.
  *
  * Bear in mind that testing non-public properties is not a good practice.
  * Use it only if you have no other way to test it.
  *
  * @param $object
  * @param $property
  * @param $type
  * @deprecated
  */
 public function seePropertyIs($object, $property, $type)
 {
     $current = $this->retrieveProperty($object, $property);
     if (in_array($type, array('int', 'bool', 'string', 'array', 'float', 'null', 'resource', 'scalar'))) {
         \PHPUnit_Framework_Assert::assertInternalType($type, $current);
         return;
     }
     \PHPUnit_Framework_Assert::assertInstanceOf($type, $current);
 }
 /**
  * @Then I should be authenticated
  */
 public function iShouldBeAuthenticated()
 {
     PHPUnit_Framework_Assert::assertInstanceOf('\\Hasmo\\Salesforce\\Authentication\\AccessToken', $this->apiResponse);
 }