Uses strpos() to find the position of the string in the input, if not found the evaluaton fails. The sub-string is passed in the constructor.
Author: Sebastian Bergmann (sebastian@phpunit.de)
Inheritance: extends PHPUnit_Framework_Constraint
コード例 #1
0
ファイル: TestCase.php プロジェクト: studio-v/nano
 public static function assertException($runnable, $class, $message)
 {
     try {
         $runnable();
         self::fail('No exception thrown');
     } catch (Exception $e) {
         if ($e instanceof $class) {
             $messageConstraint = new PHPUnit_Framework_Constraint_StringContains($message, true);
             if (!$messageConstraint->evaluate($e->getMessage())) {
                 throw $messageConstraint->fail($e->getMessage(), PHP_EOL . $e->getTraceAsString());
             }
             self::assertTrue(true);
             // update assertion counter
             self::assertTrue(true);
             // update assertion counter
         } else {
             if ($e instanceof PHPUnit_Framework_AssertionFailedError && $e->getMessage() === 'No exception thrown') {
                 throw $e;
             }
             $constraint = new PHPUnit_Framework_Constraint_IsInstanceOf($class);
             throw $constraint->fail($e, 'Expected ' . $class . ' but ' . get_class($e) . ' with message "' . $e->getMessage() . '"' . PHP_EOL . $e->getTraceAsString());
         }
     }
 }
コード例 #2
0
 public function testConstraintStringContains2()
 {
     $constraint = new PHPUnit_Framework_Constraint_StringContains('foo');
     try {
         $constraint->fail('barbazbar', 'custom message');
     } catch (PHPUnit_Framework_ExpectationFailedException $e) {
         $this->assertEquals("custom message\nFailed asserting that <string:barbazbar> contains \"foo\".", $e->getDescription());
         return;
     }
     $this->fail();
 }
コード例 #3
0
ファイル: TestFailureTest.php プロジェクト: swk/bluebox
 public function testFailureStringContains2()
 {
     $constraint = new PHPUnit_Framework_Constraint_StringContains('foo');
     try {
         $constraint->fail('barbazbar', 'custom message');
     } catch (PHPUnit_Framework_ExpectationFailedException $e) {
         $this->assertEquals("custom message\nFailed asserting that <string:barbazbar> contains \"foo\".\n", PHPUnit_Framework_TestFailure::exceptionToString($e));
         return;
     }
     $this->fail();
 }
コード例 #4
0
 public function testConstraintStringContains()
 {
     $constraint = new PHPUnit_Framework_Constraint_StringContains('foo');
     $this->assertFalse($constraint->evaluate('barbazbar'));
     $this->assertTrue($constraint->evaluate('barfoobar'));
     $this->assertEquals('contains "foo"', $constraint->toString());
     try {
         $constraint->fail('barbazbar', '');
     } catch (PHPUnit_Framework_ExpectationFailedException $e) {
         $this->assertEquals('Failed asserting that <string:barbazbar> contains "foo".', $e->getDescription());
         return;
     }
     $this->fail();
 }