本文整理汇总了PHP中PHPUnit_Framework_TestCase::assertContains方法的典型用法代码示例。如果您正苦于以下问题:PHP PHPUnit_Framework_TestCase::assertContains方法的具体用法?PHP PHPUnit_Framework_TestCase::assertContains怎么用?PHP PHPUnit_Framework_TestCase::assertContains使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PHPUnit_Framework_TestCase
的用法示例。
在下文中一共展示了PHPUnit_Framework_TestCase::assertContains方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testFactory
/**
* Test a factory.
*
* @param string $className
* @return void
*/
public function testFactory($classname, array $requiredOptions, array $options)
{
// Test that the factory does not allow a scalar option.
try {
$classname::factory(0);
$this->testCase->fail('An expected exception was not thrown');
} catch (\Zend\Mvc\Router\Exception\InvalidArgumentException $e) {
$this->testCase->assertContains('factory expects an array or Traversable set of options', $e->getMessage());
}
// Test required options.
foreach ($requiredOptions as $option => $exceptionMessage) {
$testOptions = $options;
unset($testOptions[$option]);
try {
$classname::factory($testOptions);
$this->testCase->fail('An expected exception was not thrown');
} catch (\Zend\Mvc\Router\Exception\InvalidArgumentException $e) {
$this->testCase->assertContains($exceptionMessage, $e->getMessage());
}
}
// Create the route, will throw an exception if something goes wrong.
$classname::factory($options);
// Try the same with an iterator.
$classname::factory(new ArrayIterator($options));
}
示例2: testDump
public function testDump()
{
ob_start();
Debug::dump('some string');
parent::assertContains('some', ob_get_clean());
ob_start();
Debug::dump(new \Exception('hello world'));
parent::assertContains('Exception', ob_get_clean());
}
示例3: testGetSkypeButton
/**
* @dataProvider optionsDataProvider
* @param string $username
* @param array $options
* @param array $expectedOptions
* @param string $expectedTemplate
*/
public function testGetSkypeButton($username, $options, $expectedOptions, $expectedTemplate)
{
$env = $this->getMockBuilder('\\Twig_Environment')->disableOriginalConstructor()->getMock();
$env->expects($this->once())->method('render')->with($expectedTemplate, $this->anything())->will($this->returnCallback(function ($template, $options) use($expectedOptions, $username) {
\PHPUnit_Framework_TestCase::assertArrayHasKey('name', $options['options']);
\PHPUnit_Framework_TestCase::assertEquals($expectedOptions['name'], $options['options']['name']);
\PHPUnit_Framework_TestCase::assertArrayHasKey('participants', $options['options']);
\PHPUnit_Framework_TestCase::assertEquals($expectedOptions['participants'], $options['options']['participants']);
\PHPUnit_Framework_TestCase::assertArrayHasKey('element', $options['options']);
\PHPUnit_Framework_TestCase::assertContains('skype_button_' . md5($username), $options['options']['element']);
return 'BUTTON_CODE';
}));
$this->assertEquals('BUTTON_CODE', $this->extension->getSkypeButton($env, $username, $options));
}
示例4: it_dispatches_a_static_template_request
public function it_dispatches_a_static_template_request()
{
// init
$this->setConfig();
$request = new Request($this->object->getWrappedObject()->config);
$response = new Response($this->object->getWrappedObject()->config);
// static request
$request->setPath('/test/static');
$this->dispatchRequest($request, $response);
$actual = $response->getBody();
$expectedBody = '<h1>Hello Static</h1>';
Assertions::assertContains($expectedBody, $actual, 'should inject body template');
$expectedMarkup = '<html';
Assertions::assertContains($expectedMarkup, $actual, 'should generate page container');
}
示例5: it_adds_the_app_title_to_the_page_title
public function it_adds_the_app_title_to_the_page_title()
{
// init
$config = new Config();
$this->config = $config;
$request = new Request();
$response = new Response();
// request with appended app title
$config->set('appTitle', 'app');
$config->set('pageTitleDelimiter', ' :: ');
$request->setPath('/test');
$route = (object) ["path" => "/test", "type" => "template", "template" => "/test/fixtures/static-body.html.tpl", "model" => (object) ["pageTemplate" => "/test/fixtures/index.html.tpl", "pageTitle" => 'page']];
$this->handleTemplateRouteRequest($request, $response, $route);
Assertions::assertContains('<title>page :: app</title>', $response->getBody(), 'should have page title and app title');
// request with empty page title
$route->model->pageTitle = null;
$this->handleTemplateRouteRequest($request, $response, $route);
Assertions::assertContains('<title>app</title>', $response->getBody(), 'should have app title only');
// request with empty app title
$route->model->pageTitle = 'page';
$config->set('appTitle', null);
$this->handleTemplateRouteRequest($request, $response, $route);
Assertions::assertContains('<title>page</title>', $response->getBody(), 'should have page title only');
}
示例6: assertContains
/**
* @param mixed|CM_Comparable $needle
* @param Traversable|string $haystack
* @param string $message
* @param boolean $ignoreCase
* @param boolean $checkForObjectIdentity
* @param bool $checkForNonObjectIdentity
* @throws CM_Exception_Invalid
*/
public static function assertContains($needle, $haystack, $message = '', $ignoreCase = false, $checkForObjectIdentity = true, $checkForNonObjectIdentity = false)
{
if ($needle instanceof CM_Comparable) {
if (!(is_array($haystack) || $haystack instanceof Traversable)) {
throw new CM_Exception_Invalid('Haystack is not traversable.');
}
$match = false;
foreach ($haystack as $hay) {
if ($needle->equals($hay)) {
$match = true;
break;
}
}
self::assertTrue($match, 'Needle not contained.');
} else {
parent::assertContains($needle, $haystack, $message, $ignoreCase, $checkForObjectIdentity, $checkForNonObjectIdentity);
}
}
示例7: testInvokesDefaultErrorFormatterWhenDebugIsEnabledAndThrowableCaught
/**
* @dataProvider throwables
*/
public function testInvokesDefaultErrorFormatterWhenDebugIsEnabledAndThrowableCaught($throwable)
{
$next = function () use($throwable) {
throw $throwable;
};
$this->renderer->render(ErrorHandler::TEMPLATE_ERROR, Argument::that(function ($argument) use($throwable) {
TestCase::assertInternalType('array', $argument);
TestCase::assertArrayHasKey('error', $argument);
$error = $argument['error'];
TestCase::assertContains($throwable->getMessage(), $error);
TestCase::assertContains((string) $throwable->getCode(), $error);
TestCase::assertContains($throwable->getTraceAsString(), $error);
return true;
}))->willReturn('error content');
$handler = new ErrorHandler($this->renderer->reveal(), true);
$result = $handler($this->createRequestMock()->reveal(), $this->createResponseMock()->reveal(), $next);
$this->assertInstanceOf(HtmlResponse::class, $result);
$this->assertEquals(500, $result->getStatusCode());
$this->assertEquals('error content', (string) $result->getBody());
}
示例8: assertContains
public static function assertContains($needle, $haystack, $message = '', $ignoreCase = FALSE, $checkForObjectIdentity = TRUE, $checkForNonObjectIdentity = false)
{
if ($haystack instanceof DBField) {
$haystack = (string) $haystack;
}
parent::assertContains($needle, $haystack, $message, $ignoreCase, $checkForObjectIdentity, $checkForNonObjectIdentity);
}
示例9: dataPicasaPhotoCallback
/**
* Dummy method
*
* @param string $url Path to the resource.
* @param mixed $data Either an associative array or a string to be sent with the request.
* @param array $headers An array of name-value pairs to include in the header of the request.
* @param integer $timeout Read timeout in seconds.
*
* @return JHttpResponse
*
* @since 12.3
*/
function dataPicasaPhotoCallback($url, $data, array $headers = null, $timeout = null)
{
PHPUnit_Framework_TestCase::assertContains('<title>New Title</title>', $data);
$response = new stdClass;
$response->code = 200;
$response->headers = array('Content-Type' => 'application/atom+xml');
$response->body = $data;
return $response;
}
示例10: testAdd
public function testAdd($data)
{
$count = count($this->entityGet());
$containsBeforeAdd = $this->countDataInCollection($data);
$returnOfAddMethod = $this->entityAdd($data);
if ($this->fluent) {
TestCase::assertEquals($this->entity, $returnOfAddMethod, $this->msg(self::$MSG_ADD_METHOD_NOT_FLUENT));
}
TestCase::assertContains($data, $this->entityGet(), $this->msg(self::$MSG_ADD_METHOD_DOES_NOT_ADD));
if ($this->unique && $containsBeforeAdd > 0) {
TestCase::assertCount($count, $this->entityGet(), $this->msg(self::$MSG_ADD_METHOD_NOT_UNIQUE));
} else {
TestCase::assertCount($count + 1, $this->entityGet(), $this->msg(self::$MSG_ADD_METHOD_UNIQUE));
}
return $this;
}
示例11: assertGeneratedContent
protected function assertGeneratedContent($expected, $actual)
{
$this->markTestIncomplete('Find a way to compare this!');
return parent::assertContains(preg_replace('/[\\t\\r\\n]/', '', $expected), preg_replace('/[\\t\\r\\n]/', '', $actual));
}
示例12: iShouldSeeInTheElement
/**
* @Then I should see :value in the :tag element
*/
public function iShouldSeeInTheElement($value, $tag)
{
$page = $this->getSession()->getPage();
$el = $page->find('css', $tag);
Assertions::assertNotNull($el);
$actual = $el->getText();
Assertions::assertContains($value, $actual);
}