assertInstanceOf() 공개 메소드

public assertInstanceOf ( $className, $object )
예제 #1
0
 protected function doCreate(RecordInterface $record, Version $version)
 {
     $this->testCase->assertEquals(3, $record->getUserId());
     $this->testCase->assertEquals('test', $record->getTitle());
     $this->testCase->assertInstanceOf('DateTime', $record->getDate());
     return array('success' => true, 'message' => 'You have successful create a record');
 }
예제 #2
0
 /**
  * Calls assertType() or assertInstanceOf() depending on the PHPUnit version.
  * Available from PHPUnit >= 3.5
  *
  * @param string $expected Expected value
  * @param mixed $actual Actual value
  * @param string $message Message to print if assertion is wrong
  */
 public static function assertInstanceOf($expected, $actual, $message = '')
 {
     if (self::_checkMethod('assertInstanceOf')) {
         parent::assertInstanceOf($expected, $actual, $message);
     } else {
         parent::assertType($expected, $actual, $message);
     }
 }
예제 #3
0
 public function getPostFilter()
 {
     return array(function ($request, $response, $stack) {
         $this->testCase->assertInstanceOf('PSX\\Http\\Request', $request);
         $this->testCase->assertInstanceOf('PSX\\Http\\Response', $response);
         $stack->handle($request, $response);
     });
 }
예제 #4
0
 /**
  * Asserts that a variable is of a given type.
  *
  * If $expected is an array, each string value will be used in a type
  * check. This is useful for checking if a class also implements certain
  * interfaces.
  *
  * @param string|array $expected
  * @param mixed $actual
  * @param string $message
  */
 public static function assertInstanceOf($expected, $actual, $message = '')
 {
     if (is_array($expected)) {
         foreach ($expected as $expectedSingle) {
             parent::assertInstanceOf($expectedSingle, $actual, $message);
         }
         return;
     }
     parent::assertInstanceOf($expected, $actual, $message);
 }
예제 #5
0
 /**
  * Helper method to allow PHPUnit versions < 3.5.x
  *
  * @param string $expected The expected class or interface.
  * @param mixed  $actual   The actual variable/value.
  * @param string $message  Optional error/fail message.
  *
  * @return void
  * @since 0.10.2
  */
 public static function assertInstanceOf($expected, $actual, $message = '')
 {
     if (is_callable(get_parent_class(__CLASS__) . '::') . __FUNCTION__) {
         return parent::assertInstanceOf($expected, $actual, $message);
     }
     return parent::assertType($expected, $actual, $message);
 }
 /**
  * @param object $instance
  * @param string $propertyName
  * @param mixed $testItem
  */
 public static function assertPropertyCollection($instance, $propertyName, $testItem)
 {
     $propertyAccess = new CollectionAccessor($instance, $propertyName);
     // Check default value
     \PHPUnit_Framework_TestCase::assertInstanceOf('Doctrine\\Common\\Collections\\Collection', $propertyAccess->getItems(), $propertyName . ': Default value must be instance of Collection');
     // Check default size
     \PHPUnit_Framework_TestCase::assertCount(0, $propertyAccess->getItems(), $propertyName . ': Default collection size must be 0');
     // Add first item
     \PHPUnit_Framework_TestCase::assertSame($instance, $propertyAccess->addItem($testItem), sprintf('%s::%s() - must return %s', ClassUtils::getClass($instance), $propertyAccess->getAddItemMethod(), ClassUtils::getClass($instance)));
     // Check added item
     \PHPUnit_Framework_TestCase::assertCount(1, $propertyAccess->getItems(), $propertyName . ': After add item - collection size must be 1');
     \PHPUnit_Framework_TestCase::assertInstanceOf('Doctrine\\Common\\Collections\\Collection', $propertyAccess->getItems(), $propertyName . ': After addition of a first item - property value must be instance of Collection');
     \PHPUnit_Framework_TestCase::assertEquals([$testItem], $propertyAccess->getItems()->toArray(), $propertyName . ': After addition of a first item - collections must be equals');
     // Add already added item
     $propertyAccess->addItem($testItem);
     \PHPUnit_Framework_TestCase::assertCount(1, $propertyAccess->getItems(), $propertyName . ': After addition already added item - collection size must be same and equal 1');
     // Remove item
     \PHPUnit_Framework_TestCase::assertSame($instance, $propertyAccess->removeItem($testItem), sprintf('%s:%s() - must return %s', ClassUtils::getClass($instance), $propertyAccess->getRemoveItemMethod(), ClassUtils::getClass($instance)));
     \PHPUnit_Framework_TestCase::assertCount(0, $propertyAccess->getItems(), $propertyName . ': After removal of a single item - collection size must be 0');
     // Remove already removed item
     $propertyAccess->removeItem($testItem);
     \PHPUnit_Framework_TestCase::assertCount(0, $propertyAccess->getItems(), $propertyName . ': After removal already removed item - collection size must be same and equal 0');
     \PHPUnit_Framework_TestCase::assertNotContains($testItem, $propertyAccess->getItems()->toArray(), $propertyName . ': After removal of a single item - collection must not contains test item');
 }
 public function testGet()
 {
     $get = $this->entityGet();
     if (is_object($get)) {
         TestCase::assertInstanceOf("Countable", $get, $this->msg(self::$MSG_GET_METHOD_MUST_RETURN_COUNTABLE_OBJECT));
         TestCase::assertInstanceOf("Traversable", $get, $this->msg(self::$MSG_GET_METHOD_MUST_RETURN_TRAVERSABLE_OBJECT));
     } elseif (!is_null($get)) {
         TestCase::assertInternalType("array", $get, $this->msg(self::$MSG_GET_METHOD_MUST_RETURN_AN_ARRAY));
     } else {
         throw new AssertionFailedError($this->msg(self::$MSG_GET_METHOD_MUST_NOT_RETURN_NULL));
     }
 }
예제 #8
0
파일: lib.php 프로젝트: nickread/moodle
 /**
  * @deprecated since 2.3
  * @static
  * @param mixed $actual
  * @param mixed $expected
  * @param string $message
  */
 public static function assertIsA($actual, $expected, $message = '')
 {
     parent::assertInstanceOf($expected, $actual, $message);
 }
예제 #9
0
파일: TestCommand.php 프로젝트: seytar/psx
 public function onExecute(Parameters $parameters, OutputInterface $output)
 {
     // test properties
     $this->testCase->assertInstanceOf('PSX\\Loader\\Context', $this->context);
     $this->testCase->assertInstanceOf('PSX\\Config', $this->config);
 }
예제 #10
0
 /**
  * @test
  */
 public function emptyHandlers()
 {
     $handlers = $this->handlerContainer->getHandlers();
     parent::assertInstanceOf(\Traversable::class, $handlers);
     parent::assertEmpty($handlers);
 }
예제 #11
0
파일: TestCase.php 프로젝트: ovr/phpsa
 /**
  * @param CompiledExpression|null $actual
  * @param string $message
  */
 protected function assertInstanceOfCompiledExpression($actual, $message = '')
 {
     parent::assertInstanceOf(CompiledExpression::class, $actual, $message);
 }
예제 #12
0
 /**
  * Checks whether the data we received as post is converted to the right
  * types
  *
  * @param \PHPUnit_Framework_TestCase $testCase
  * @param \PSX\Data\RecordInterface $record
  */
 public static function assertRecord(\PHPUnit_Framework_TestCase $testCase, RecordInterface $record)
 {
     $testCase->assertInternalType('array', $record->getArray());
     $testCase->assertEquals(1, count($record->getArray()));
     $testCase->assertEquals(['bar'], $record->getArray());
     $testCase->assertInternalType('array', $record->getArrayComplex());
     $testCase->assertEquals(2, count($record->getArrayComplex()));
     $testCase->assertInstanceOf('PSX\\Data\\RecordInterface', $record->getArrayComplex()[0]);
     $testCase->assertEquals(['foo' => 'bar'], $record->getArrayComplex()[0]->getRecordInfo()->getFields());
     $testCase->assertInstanceOf('PSX\\Data\\RecordInterface', $record->getArrayComplex()[1]);
     $testCase->assertEquals(['foo' => 'foo'], $record->getArrayComplex()[1]->getRecordInfo()->getFields());
     $testCase->assertInternalType('array', $record->getArrayChoice());
     $testCase->assertEquals(3, count($record->getArrayChoice()));
     $testCase->assertInstanceOf('PSX\\Data\\RecordInterface', $record->getArrayChoice()[0]);
     $testCase->assertEquals(['foo' => 'baz'], $record->getArrayChoice()[0]->getRecordInfo()->getFields());
     $testCase->assertInstanceOf('PSX\\Data\\RecordInterface', $record->getArrayChoice()[1]);
     $testCase->assertEquals(['bar' => 'bar'], $record->getArrayChoice()[1]->getRecordInfo()->getFields());
     $testCase->assertInstanceOf('PSX\\Data\\RecordInterface', $record->getArrayChoice()[2]);
     $testCase->assertEquals(['foo' => 'foo'], $record->getArrayChoice()[2]->getRecordInfo()->getFields());
     $testCase->assertInternalType('boolean', $record->getBoolean());
     $testCase->assertEquals(true, $record->getBoolean());
     $testCase->assertInstanceOf('PSX\\Data\\RecordInterface', $record->getChoice());
     $testCase->assertEquals(['foo' => 'bar'], $record->getComplex()->getRecordInfo()->getFields());
     $testCase->assertInstanceOf('PSX\\Data\\RecordInterface', $record->getComplex());
     $testCase->assertEquals(['foo' => 'bar'], $record->getComplex()->getRecordInfo()->getFields());
     $testCase->assertInstanceOf('PSX\\DateTime\\Date', $record->getDate());
     $testCase->assertEquals('2015-05-01', $record->getDate()->format('Y-m-d'));
     $testCase->assertInstanceOf('PSX\\DateTime', $record->getDateTime());
     $testCase->assertEquals('2015-05-01T13:37:14Z', $record->getDateTime()->format('Y-m-d\\TH:i:s\\Z'));
     $testCase->assertInstanceOf('PSX\\DateTime\\Duration', $record->getDuration());
     $testCase->assertEquals('000100000000', $record->getDuration()->format('%Y%M%D%H%I%S'));
     $testCase->assertInternalType('float', $record->getFloat());
     $testCase->assertEquals(13.37, $record->getFloat());
     $testCase->assertInternalType('integer', $record->getInteger());
     $testCase->assertEquals(7, $record->getInteger());
     $testCase->assertInternalType('string', $record->getString());
     $testCase->assertEquals('bar', $record->getString());
     $testCase->assertInstanceOf('PSX\\DateTime\\Time', $record->getTime());
     $testCase->assertEquals('13:37:14', $record->getTime()->format('H:i:s'));
 }
 protected function prepare()
 {
     $this->container = \Mockery::mock(Container::class)->makePartial();
     $schemaMapper = \Mockery::mock(SchemaMapper::class)->makePartial();
     $schemaMapper->shouldReceive('buildCredentialsFromInlineFormat')->once()->passthru();
     $this->container->shouldReceive('resolve')->once()->with('Domain\\Mapper\\Schema')->andReturn($schemaMapper);
     $credentialsMatcher = \Mockery::on(function ($args) {
         /** @var CredentialsInterface $credentials */
         $credentials = $args[0];
         \PHPUnit_Framework_TestCase::assertInstanceOf(CredentialsInterface::class, $credentials);
         $actual = $credentials->toArray();
         $expected = ["username" => "user1", "password" => "pass2", "host" => "sample.host", "database" => "sample_database"];
         if ($expected != $actual) {
             \PHPUnit_Framework_TestCase::fail('Check credentials format or sample.');
         }
         return true;
     });
     $pdo = \Mockery::mock(\PDO::class);
     $this->container->shouldReceive('resolve')->once()->with('Persistence\\Storage\\PDO', $credentialsMatcher)->andReturn($pdo);
     $storageMatcher = \Mockery::on(function ($args) use($pdo) {
         /** @var StorageInterface $storage */
         $storage = $args[0];
         if ($pdo != $storage) {
             \PHPUnit_Framework_TestCase::fail('Check pipes.');
         }
         return true;
     });
     $gateway = \Mockery::mock(MySQLGateway::class);
     $this->container->shouldReceive('resolve')->once()->with('Persistence\\Gateway\\Schema\\MySQL', $storageMatcher)->andReturn($gateway);
     $gatewayAndMapperMatcher = \Mockery::on(function ($args) use($gateway, $schemaMapper) {
         if ($args[0] != $gateway) {
             \PHPUnit_Framework_TestCase::fail('Gateway mismatch.');
         }
         if ($args[1] != $schemaMapper) {
             \PHPUnit_Framework_TestCase::fail('Mapper mismatch.');
         }
         return true;
     });
     $this->schemaService = \Mockery::mock(SchemaService::class);
     $this->container->shouldReceive('resolve')->once()->with('Infrastructure\\Services\\Schema', $gatewayAndMapperMatcher)->andReturn($this->schemaService);
     $classCommand = '\\DatabaseInspect\\Console\\Command\\DetailsCommand[execute]';
     $this->command = \Mockery::mock($classCommand, [$this->container])->makePartial();
     $this->input = \Mockery::mock(ArgvInput::class);
     $this->input->shouldReceive('getArgument')->once()->andReturn('user1:pass2@sample.host/sample_database');
     $this->output = \Mockery::mock(ConsoleOutput::class);
 }
예제 #14
0
 protected function doCreate(RecordInterface $record, Version $version)
 {
     $this->testCase->assertEquals(3, $record->getUserId());
     $this->testCase->assertEquals('test', $record->getTitle());
     $this->testCase->assertInstanceOf('DateTime', $record->getDate());
 }
예제 #15
0
 public function test_debug_function_is_called()
 {
     $this->http->method('request')->will($this->returnCallback(function () {
         return new \Communique\RESTClientResponse(200, 'response+payload', array('X-PoweredBy' => 'Dreams'));
     }));
     $rest = new \Communique\Communique('http://domain.com/', array(), $this->http);
     $rest->get('users', array('request' => 'payload'), array('Foo' => 'Bar'), function ($request, $response) {
         PHPUnit_Framework_TestCase::assertInstanceOf('\\Communique\\RESTClientRequest', $request);
         PHPUnit_Framework_TestCase::assertEquals($request->url, 'http://domain.com/users');
         PHPUnit_Framework_TestCase::assertEquals($request->payload, array('request' => 'payload'));
         PHPUnit_Framework_TestCase::assertEquals($request->headers, array('Foo' => 'Bar'));
         PHPUnit_Framework_TestCase::assertInstanceOf('\\Communique\\RESTClientResponse', $response);
         PHPUnit_Framework_TestCase::assertEquals($response->status, 200);
         PHPUnit_Framework_TestCase::assertEquals($response->payload, 'response+payload');
         PHPUnit_Framework_TestCase::assertEquals($response->headers, array('X-PoweredBy' => 'Dreams'));
     });
 }
예제 #16
0
 /**
  * @test
  */
 public function getUnbuffered()
 {
     $ipProvider = $this->getIpProvider(false);
     parent::assertInstanceOf(IpProvider::class, $ipProvider);
 }
예제 #17
0
 /**
  * @test
  */
 public function emptyProcessors()
 {
     $processors = $this->processorContainer->getProcessors();
     parent::assertInstanceOf(\Traversable::class, $processors);
     parent::assertEmpty($processors);
 }
예제 #18
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
  */
 public static function assertInstanceOf($expected, $actual, $message = '')
 {
     if (self::$_assert_type_compatability) {
         return self::assertType($expected, $actual, $message);
     }
     return parent::assertInstanceOf($expected, $actual, $message);
 }
예제 #19
0
파일: lib.php 프로젝트: numbas/moodle
 /**
  * @deprecated since 2.3
  * @static
  * @param mixed $actual
  * @param mixed $expected
  * @param string $message
  * @return void
  */
 public static function assertIsA($actual, $expected, $message = '')
 {
     if ($expected === 'array') {
         parent::assertEquals('array', gettype($actual), $message);
     } else {
         parent::assertInstanceOf($expected, $actual, $message);
     }
 }
예제 #20
0
 /**
  * @test
  */
 public function formatterNotEmpty()
 {
     $formatter = $this->formatterContainer->getFormatter();
     parent::assertInstanceOf(FormatterInterface::class, $formatter);
 }
예제 #21
0
 /**
  * @dataProvider multipleTypeDataProvider
  * @param bool $isMultiple
  */
 public function testCreateEntitiesToIdsTransformer($isMultiple)
 {
     $options = array('em' => $this->getMockEntityManager(), 'multiple' => $isMultiple, 'class' => 'TestClass', 'property' => 'id', 'queryBuilder' => function ($repository, array $ids) {
         return $repository->createQueryBuilder('o')->where('o.id IN (:values)')->setParameter('values', $ids);
     }, 'values_delimiter' => ',');
     $builder = $this->getMockBuilder('Symfony\\Component\\Form\\Test\\FormBuilderInterface')->setMethods(array('addViewTransformer', 'addEventSubscriber'))->getMockForAbstractClass();
     $builder->expects($this->at(0))->method('addViewTransformer')->with($this->callback(function ($transformer) use($options, $isMultiple) {
         if ($isMultiple) {
             \PHPUnit_Framework_TestCase::assertInstanceOf('Oro\\Bundle\\FormBundle\\Form\\DataTransformer\\EntitiesToIdsTransformer', $transformer);
         } else {
             \PHPUnit_Framework_TestCase::assertInstanceOf('Oro\\Bundle\\FormBundle\\Form\\DataTransformer\\EntityToIdTransformer', $transformer);
         }
         \PHPUnit_Framework_TestCase::assertAttributeEquals($options['em'], 'em', $transformer);
         \PHPUnit_Framework_TestCase::assertAttributeEquals($options['class'], 'className', $transformer);
         \PHPUnit_Framework_TestCase::assertAttributeEquals($options['property'], 'property', $transformer);
         \PHPUnit_Framework_TestCase::assertAttributeEquals($options['queryBuilder'], 'queryBuilderCallback', $transformer);
         return true;
     }))->will($this->returnSelf());
     if ($isMultiple) {
         $builder->expects($this->at(1))->method('addViewTransformer')->will($this->returnSelf());
     }
     $this->type = new EntityIdentifierType($this->getMockManagerRegistry());
     $this->type->buildForm($builder, $options);
 }
 /**
  * Assert there is possibility of creating an instance
  * of the given class.
  *
  * @param string $class
  */
 protected static function assertClassIsInstantiable($class)
 {
     $object = new $class();
     parent::assertInstanceOf($class, $object);
     unset($object);
 }
예제 #23
0
 /**
  * @test
  * @dataProvider getInstanceValues
  */
 public function hasCollectionInterface()
 {
     parent::assertInstanceOf(CollectionInterface::class, $this->getCollectionInstance());
 }