assertThat() public static method

Evaluates a PHPUnit_Framework_Constraint matcher object.
public static assertThat ( mixed $value, PHPUnit_Framework_Constraint $constraint, string $message = '' )
$value mixed
$constraint PHPUnit_Framework_Constraint
$message string
Ejemplo n.º 1
0
 /**
  * Asserts response headers match with the media types defined.
  *
  * @param string[] $headers
  * @param SchemaManager $schemaManager
  * @param string $path percent-encoded path used on the request.
  * @param string $httpMethod
  * @param int $httpCode
  * @param string $message
  */
 public function assertResponseHeadersMatch(array $headers, SchemaManager $schemaManager, $path, $httpMethod, $httpCode, $message = '')
 {
     if (!$schemaManager->findPathInTemplates($path, $template, $params)) {
         throw new \RuntimeException('Request URI does not match with any swagger path definition');
     }
     $constraint = new ResponseHeadersConstraint($schemaManager, $template, $httpMethod, $httpCode);
     Assert::assertThat($headers, $constraint, $message);
 }
Ejemplo n.º 2
0
 /**
  * Evaluates the constraint for test case
  *
  * @param string $testCaseName
  * @return bool
  */
 protected function matches($testCaseName)
 {
     $result = true;
     foreach ($this->constraints as $constraint) {
         \PHPUnit_Framework_Assert::assertThat("", $constraint);
         $result = $result && $constraint->getResult();
     }
     return $result;
 }
 /**
  * @param mixed  $needle
  * @param mixed  $haystack
  * @param string $message
  * @param bool   $ignoreCase
  * @param bool   $checkForObjectIdentity
  * @param bool   $checkForNonObjectIdentity
  */
 public static function assertNotContains($needle, $haystack, $message = '', $ignoreCase = false, $checkForObjectIdentity = true, $checkForNonObjectIdentity = false)
 {
     if (is_array($haystack) || is_object($haystack) && $haystack instanceof \Traversable) {
         $constraint = new \PHPUnit_Framework_Constraint_Not(self::contains($needle, $checkForObjectIdentity, $checkForNonObjectIdentity));
     } elseif (is_string($haystack)) {
         if (!is_string($needle)) {
             throw \PHPUnit_Util_InvalidArgumentHelper::factory(1, 'string');
         }
         $constraint = new \PHPUnit_Framework_Constraint_Not(new \PHPUnit_Framework_Constraint_StringContains($needle, $ignoreCase));
     } else {
         throw \PHPUnit_Util_InvalidArgumentHelper::factory(2, 'array, traversable or string');
     }
     \PHPUnit_Framework_Assert::assertThat($haystack, $constraint, $message);
 }
 /**
  * @test
  */
 public function thatHandles()
 {
     $messages = array(new Message(self::DUMMY_MESSAGE_UNIQUE_ID, self::DUMMY_MESSAGE_ID, self::DUMMY_MESSAGE_SUBJECT, self::DUMMY_MESSAGE_CONTENT, $this->getDummyFrom(), self::DUMMY_MESSAGE_TO, self::DUMMY_MESSAGE_REFERENCE));
     $strategies = array($this->strategy);
     $this->provider->expects($this->once())->method('fetchMessagesToProcess')->will($this->returnValue($messages));
     $this->strategyHolder->expects($this->once())->method('getStrategies')->will($this->returnValue($strategies));
     $this->context->expects($this->exactly(count($strategies)))->method('setStrategy')->with($this->isInstanceOf('\\Diamante\\EmailProcessingBundle\\Model\\Processing\\Strategy'));
     $this->context->expects($this->exactly(count($messages) * count($strategies)))->method('execute')->with($this->isInstanceOf('Diamante\\EmailProcessingBundle\\Model\\Message'));
     $this->provider->expects($this->once())->method('markMessagesAsProcessed')->with($this->logicalAnd($this->isType(\PHPUnit_Framework_Constraint_IsType::TYPE_ARRAY), $this->countOf(count($messages)), $this->callback(function ($other) {
         $result = true;
         foreach ($other as $message) {
             $constraint = \PHPUnit_Framework_Assert::isInstanceOf('Diamante\\EmailProcessingBundle\\Model\\Message');
             try {
                 \PHPUnit_Framework_Assert::assertThat($message, $constraint);
             } catch (\PHPUnit_Framework_ExpectationFailedException $e) {
                 $result = false;
             }
         }
         return $result;
     })));
     $this->manager->handle($this->provider);
 }
 /**
  * @test
  */
 public function thatHandlesAndMarksMessages()
 {
     $messages = $this->getMessages();
     $strategies = array($this->strategy);
     $this->settings->expects($this->any())->method('getDeleteProcessedMessages')->will($this->returnValue(false));
     $this->provider->expects($this->once())->method('fetchMessagesToProcess')->will($this->returnValue($messages));
     $this->strategyHolder->expects($this->once())->method('getStrategies')->will($this->returnValue($strategies));
     $this->context->expects($this->exactly(count($strategies)))->method('setStrategy')->with($this->isInstanceOf('\\Diamante\\EmailProcessingBundle\\Model\\Processing\\Strategy'));
     $this->context->expects($this->exactly(count($messages) * count($strategies)))->method('execute')->with($this->isInstanceOf('Diamante\\EmailProcessingBundle\\Model\\Message'));
     $this->provider->expects($this->once())->method('markMessagesAsProcessed')->with($this->logicalAnd($this->isType(\PHPUnit_Framework_Constraint_IsType::TYPE_ARRAY), $this->countOf(count($messages)), $this->callback(function ($other) {
         $result = true;
         foreach ($other as $message) {
             $constraint = \PHPUnit_Framework_Assert::isInstanceOf('Diamante\\EmailProcessingBundle\\Model\\Message');
             try {
                 \PHPUnit_Framework_Assert::assertThat($message, $constraint);
             } catch (\PHPUnit_Framework_ExpectationFailedException $e) {
                 $result = false;
             }
         }
         return $result;
     })));
     $this->manager->handle($this->provider);
 }
Ejemplo n.º 6
0
 /**
  * Asserts that the two strings match but that all whitespaces are 
  * not necessarily equal.
  *
  * @param array $expected
  * @param array $actual
  * @param string $message
  */
 public static function assertStringMatchIgnoreWhitespace($expected, $actual, $message = '')
 {
     PHPUnit_Framework_Assert::assertThat($actual, new PHPUnit_Extensions_Constraint_StringMatchIgnoreWhitespace($expected), $message);
 }
Ejemplo n.º 7
0
 /**
  * Checks whether the last JSON response contains provided array.
  * The response is converted to array with json_decode($response, true)
  * Thus, JSON is represented by associative array.
  * This method matches that response array contains provided array.
  *
  * Examples:
  *
  * ``` php
  * <?php
  * // response: {name: john, email: john@gmail.com}
  * $I->seeResponseContainsJson(array('name' => 'john'));
  *
  * // response {user: john, profile: { email: john@gmail.com }}
  * $I->seeResponseContainsJson(array('email' => '*****@*****.**'));
  *
  * ?>
  * ```
  *
  * This method recursively checks if one array can be found inside of another.
  *
  * @param array $json
  * @part json
  */
 public function seeResponseContainsJson($json = [])
 {
     \PHPUnit_Framework_Assert::assertThat($this->connectionModule->_getResponseContent(), new JsonContains($json));
 }
Ejemplo n.º 8
0
/**
 * Evaluates a PHPUnit_Framework_Constraint matcher object.
 *
 * @param  mixed$value
 * @param  PHPUnit_Framework_Constraint $constraint
 * @param  string   $message
 * @since  Method available since Release 3.0.0
 */
function assertThat($value, PHPUnit_Framework_Constraint $constraint, $message = '')
{
    return PHPUnit_Framework_Assert::assertThat($value, $constraint, $message);
}
Ejemplo n.º 9
0
 /**
  * Asserts protocol version is valid.
  *
  * Protocol version MUST be:
  * - String type.
  * - Valid HTTP protocol version number.
  *
  * @param string $protocolVersion
  * @param string $message
  */
 public static function assertValid($protocolVersion, $message = '')
 {
     Assert::assertThat($protocolVersion, new self(), $message);
 }
Ejemplo n.º 10
0
 public function processObjectFreeze()
 {
     PHPUnit_Framework_Assert::assertThat(true, PHPUnit_Framework_Assert::isTrue());
 }
Ejemplo n.º 11
0
 /**
  * @Then the response should be json/JSON
  * @Then the response is json/JSON
  */
 public function theResponseIsJson()
 {
     Assert::assertThat(static::$response->headers->get('Content-Type'), Assert::logicalOr(Assert::stringStartsWith('application/json'), Assert::stringStartsWith('text/javascript')));
     Assert::assertJson($this->getResponseContent());
 }
Ejemplo n.º 12
0
 public function shouldNotContain($value)
 {
     Assert::assertThat($this->it, Assert::logicalNot(Assert::contains($value)));
 }
 public static function assertRequestIsDelete(RequestInterface $request)
 {
     Assert::assertThat($request, static::isDelete());
 }
Ejemplo n.º 14
0
 /**
  * Asserts two objects are the same type but not the same instance.
  *
  * @param object $original
  * @param object $new
  * @param string $message
  */
 public static function assertImmutable($original, $new, $message = '')
 {
     Assert::assertThat($new, new self($original), $message);
 }
Ejemplo n.º 15
0
 /**
  * @param Spec $spec
  * @param string $class
  * @param mixed $actual
  * @param string $msg
  */
 protected static final function assertDefinitionSchema(Spec $spec, $class, $actual, $msg = '')
 {
     Assert::assertThat($actual, new JsonSchemaConstraint($spec->getDefinition($class)), $msg);
 }
 /**
  * Run Update Customer Entity test
  *
  * @param Customer $initialCustomer
  * @param Customer $customer
  * @param Address $address
  * @param AssertCustomerInfoSuccessSavedMessage $assertCustomerInfoSuccessSavedMessage
  * @return void
  */
 public function test(Customer $initialCustomer, Customer $customer, Address $address, AssertCustomerInfoSuccessSavedMessage $assertCustomerInfoSuccessSavedMessage)
 {
     // Preconditions
     $initialCustomer->persist();
     // Steps
     $this->objectManager->create('Magento\\Customer\\Test\\TestStep\\LoginCustomerOnFrontendStep', ['customer' => $initialCustomer])->run();
     $this->customerAccountIndex->getInfoBlock()->openEditContactInfo();
     $this->customerAccountEdit->getAccountInfoForm()->fill($customer);
     $this->customerAccountEdit->getAccountInfoForm()->submit();
     \PHPUnit_Framework_Assert::assertThat($this->getName(), $assertCustomerInfoSuccessSavedMessage);
     $this->cmsIndex->getCmsPageBlock()->waitPageInit();
     $this->customerAccountIndex->getDashboardAddress()->editBillingAddress();
     $this->customerAddressEdit->getEditForm()->fill($address);
     $this->customerAddressEdit->getEditForm()->saveAddress();
 }
 /**
  * Perform assert.
  *
  * @param AbstractConstraint $assert
  * @param InjectableFixture $product
  * @return void
  */
 protected function productCompareAssert(AbstractConstraint $assert, InjectableFixture $product)
 {
     $assert->configure(['catalogProductView' => $this->catalogProductView, 'product' => $product]);
     \PHPUnit_Framework_Assert::assertThat($this->getName(), $assert);
 }
Ejemplo n.º 18
0
 /**
  * Assert a value with a constraint.
  * 
  * @param mixed      $value
  * @param Constraint $constraint
  * @param string     $message
  * 
  * @return self
  */
 protected function assert($value, Constraint $constraint, $message = '')
 {
     Assert::assertThat($value, $constraint, $message);
     return $this;
 }
Ejemplo n.º 19
0
 public function toBeJson()
 {
     if ($this->negate) {
         a::assertThat($this->actual, a::logicalAnd(a::isType('string'), a::logicalNot(a::isJson())));
     } else {
         a::assertJson($this->actual);
     }
 }
 /**
  * Assert that a JSON document matches a given JSON schema.
  *
  * @param mixed $jsonDocument A JSON document. If this is a string, it will
  *                            be assumed to be an encoded JSON document
  * @param array $schema       A JSON schema
  * @return void
  */
 public static function assertJsonDocumentMatchesSchema($jsonDocument, $schema)
 {
     Assert::assertThat($jsonDocument, new JsonValueMatchesSchema($schema));
 }
Ejemplo n.º 21
0
 /**
  * Checks that haystack doesn't attend
  *  
  * @param        $haystack
  * @param        $constraint
  * @param string $message
  */
 protected function assertThatItsNot($haystack, $constraint, $message)
 {
     $constraint = new \PHPUnit_Framework_Constraint_Not($constraint);
     \PHPUnit_Framework_Assert::assertThat($haystack, $constraint, $message);
 }
Ejemplo n.º 22
0
 public static function assertJsonStringEqualsJsonString($expectedJson, $actualJson, $message = '')
 {
     Assertions::assertJson($expectedJson, $message);
     Assertions::assertJson($actualJson, $message);
     $expected = json_decode($expectedJson);
     $actual = json_decode($actualJson);
     Assertions::assertThat($actual, new ConstraintIsSimilar($expected), $message);
 }
 /**
  * Run Update Customer Entity test
  *
  * @param Customer $initialCustomer
  * @param Customer $customer
  * @param Address $address
  * @param AssertCustomerInfoSuccessSavedMessage $assertCustomerInfoSuccessSavedMessage
  * @return void
  */
 public function test(Customer $initialCustomer, Customer $customer, Address $address, AssertCustomerInfoSuccessSavedMessage $assertCustomerInfoSuccessSavedMessage)
 {
     // Preconditions
     $initialCustomer->persist();
     // Steps
     $this->cmsIndex->open();
     $this->cmsIndex->getLinksBlock()->openLink('Log In');
     sleep(3);
     $this->customerAccountLogin->getLoginBlock()->fill($initialCustomer);
     $this->customerAccountLogin->getLoginBlock()->submit();
     $this->customerAccountIndex->getInfoBlock()->openEditContactInfo();
     $this->customerAccountEdit->getAccountInfoForm()->fill($customer);
     $this->customerAccountEdit->getAccountInfoForm()->submit();
     \PHPUnit_Framework_Assert::assertThat($this->getName(), $assertCustomerInfoSuccessSavedMessage);
     $this->customerAccountIndex->getDashboardAddress()->editBillingAddress();
     $this->customerAddressEdit->getEditForm()->fill($address);
     $this->customerAddressEdit->getEditForm()->saveAddress();
 }
Ejemplo n.º 24
0
 /**
  * Assert that an html button tag does not exist inside the current tag
  * @param  string|array   $selector
  * @param  array          $filters
  * @param  string         $message
  * @return Functest_Node  $this
  */
 public static function assertHasNoButton($node, $selector, array $filters = array(), $message = NULL)
 {
     return \PHPUnit_Framework_Assert::assertThat($node, new Constraint_Locator_Negative('button', $selector, $filters), $message);
 }