本文整理汇总了PHP中PHPUnit_Framework_TestCase::assertInstanceOf方法的典型用法代码示例。如果您正苦于以下问题:PHP PHPUnit_Framework_TestCase::assertInstanceOf方法的具体用法?PHP PHPUnit_Framework_TestCase::assertInstanceOf怎么用?PHP PHPUnit_Framework_TestCase::assertInstanceOf使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PHPUnit_Framework_TestCase
的用法示例。
在下文中一共展示了PHPUnit_Framework_TestCase::assertInstanceOf方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: doCreate
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: assertInstanceOf
/**
* 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: getPostFilter
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: assertInstanceOf
/**
* 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: assertInstanceOf
/**
* 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);
}
示例6: assertPropertyCollection
/**
* @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');
}
示例7: testGet
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: assertIsA
/**
* @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: onExecute
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: emptyHandlers
/**
* @test
*/
public function emptyHandlers()
{
$handlers = $this->handlerContainer->getHandlers();
parent::assertInstanceOf(\Traversable::class, $handlers);
parent::assertEmpty($handlers);
}
示例11: assertInstanceOfCompiledExpression
/**
* @param CompiledExpression|null $actual
* @param string $message
*/
protected function assertInstanceOfCompiledExpression($actual, $message = '')
{
parent::assertInstanceOf(CompiledExpression::class, $actual, $message);
}
示例12: assertRecord
/**
* 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'));
}
示例13: prepare
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: doCreate
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: test_debug_function_is_called
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'));
});
}