fail() public static method

Fails a test with the given message.
public static fail ( string $message = '' )
$message string
Exemplo n.º 1
0
 /**
  * Deletes a file
  *
  * ``` php
  * <?php
  * $I->deleteFile('composer.lock');
  * ?>
  * ```
  *
  * @param $filename
  */
 public function deleteFile($filename)
 {
     if (!file_exists($this->absolutizePath($filename))) {
         \PHPUnit_Framework_Assert::fail('file not found');
     }
     unlink($this->absolutizePath($filename));
 }
Exemplo n.º 2
0
 /**
  * Count the current number of messages on the queue.
  *
  * @param $queue Queue Name
  *
  * @return int Count
  */
 public function getMessagesCurrentCountOnQueue($queue)
 {
     try {
         return $this->queue->statsTube($queue)['current-jobs-ready'];
     } catch (\Pheanstalk_Exception_ServerException $e) {
         \PHPUnit_Framework_Assert::fail("queue [{$queue}] not found");
     }
 }
Exemplo n.º 3
0
 protected function _testCreate()
 {
     if ($this->_model->getId()) {
         \PHPUnit_Framework_Assert::fail("Can't run creation test for models with defined id");
     }
     $this->_model->save();
     \PHPUnit_Framework_Assert::assertNotEmpty($this->_model->getId(), 'CRUD Create error');
 }
Exemplo n.º 4
0
 public function clearQueue($queue)
 {
     try {
         $this->queue->clearQueue($queue);
     } catch (\Http_Exception $ex) {
         \PHPUnit_Framework_Assert::fail("queue [{$queue}] not found");
     }
 }
Exemplo n.º 5
0
 /**
  * @Then response status code is :code
  *
  * @param int $code
  */
 public function responseStatusCodeIs($code)
 {
     if (!$this->api->getClient()->getLastResponse()) {
         PHPUnit_Framework_Assert::fail();
     }
     $statusCode = $this->api->getClient()->getLastResponse()->getStatusCode();
     PHPUnit_Framework_Assert::assertEquals($code, $statusCode);
 }
Exemplo n.º 6
0
 /**
  * Checks element visibility.
  * Fails if element exists but is invisible to user.
  *
  * @param $css
  */
 public function seeElement($css)
 {
     $el = $this->session->getPage()->find('css', $css);
     if (!$el) {
         \PHPUnit_Framework_Assert::fail("Element {$css} not found");
     }
     \PHPUnit_Framework_Assert::assertTrue($this->session->getDriver()->isVisible($el->getXpath()));
 }
Exemplo n.º 7
0
 /**
  * @param PHPUnit_Framework_MockObject_Invocation $invocation
  * @return the invocation of the Entry with matching parameters.
  */
 public function invoke(PHPUnit_Framework_MockObject_Invocation $invocation)
 {
     foreach ($this->return_map as $entry) {
         if ($entry->matches($invocation)) {
             return $entry->invoke($invocation);
         }
     }
     PHPUnit_Framework_Assert::fail(sprintf('No return value defined for %s', PHPUnit_Util_Type::toString($invocation->parameters)));
 }
Exemplo n.º 8
0
 /**
  * @return Generator
  */
 public function getIterator()
 {
     foreach ($this->stack as $index => $resource) {
         if (!is_object($resource)) {
             PHPUnit::fail(sprintf('Encountered a resource that is not an object at index %d', $index));
         }
         (yield $index => new ResourceTester($resource, $index));
     }
 }
Exemplo n.º 9
0
 /**
  * @Given /^there is a Content Type "([^"]*)" with the id "([^"]*)"$/
  */
 public function thereIsAContentTypeWithId($contentTypeIdentifier, $id)
 {
     try {
         $contentType = $this->contentTypeService->loadContentTypeByIdentifier($contentTypeIdentifier);
         Assertion::assertEquals($id, $contentType->id);
     } catch (NotFoundException $e) {
         Assertion::fail("No ContentType with the identifier '{$contentTypeIdentifier}' could be found.");
     }
 }
Exemplo n.º 10
0
 /**
  * @return Generator
  */
 public function getIterator()
 {
     foreach ($this->errors as $index => $error) {
         if (!is_object($error)) {
             PHPUnit::fail(sprintf('Encountered an error that is not an object at index %d', $index));
         }
         (yield $index => new ErrorTester($error));
     }
 }
Exemplo n.º 11
0
 /**
  * @access public
  */
 protected function runTest()
 {
     $timer = new Benchmark_Timer();
     $timer->start();
     parent::runTest();
     $timer->stop();
     if ($this->fMaxRunningTime != 0 && $timer->timeElapsed() > $this->fMaxRunningTime) {
         PHPUnit_Framework_Assert::fail(sprintf('expected running time: <= %s but was: %s', $this->fMaxRunningTime, $timer->timeElapsed()));
     }
 }
Exemplo n.º 12
0
function apc_store($key, $value)
{
    if (count($GLOBALS['expected_apc_store_calls']) == 0) {
        \PHPUnit_Framework_Assert::fail("Unexpected apc_store({$key}, {$value})");
    }
    $call = array_shift($GLOBALS['expected_apc_store_calls']);
    \PHPUnit_Framework_Assert::assertEquals($call['args'][0], $key);
    \PHPUnit_Framework_Assert::assertEquals($call['args'][1], $value);
    return $call['ret'];
}
Exemplo n.º 13
0
 /**
  * Create a document tester from a raw HTTP response content.
  *
  * @param string $responseContent
  * @return DocumentTester
  */
 public static function create($responseContent)
 {
     $decoded = json_decode($responseContent);
     if (JSON_ERROR_NONE !== json_last_error()) {
         PHPUnit::fail('Invalid response JSON: ' . json_last_error_msg());
     }
     if (!is_object($decoded)) {
         PHPUnit::fail('Invalid JSON API response content.');
     }
     return new self($decoded);
 }
Exemplo n.º 14
0
 /**
  * @Given /^Using server "([^"]*)"$/
  */
 public function usingServer($server)
 {
     if ($server === 'LOCAL') {
         $this->baseUrl = $this->localBaseUrl;
         $this->currentServer = 'LOCAL';
     } elseif ($server === 'REMOTE') {
         $this->baseUrl = $this->remoteBaseUrl;
         $this->currentServer = 'REMOTE';
     } else {
         PHPUnit_Framework_Assert::fail("Server can only be LOCAL or REMOTE");
     }
 }
 /**
  * @param PHPUnit_Framework_MockObject_Invocation $invocation
  * @return the invocation of the Entry with matching parameters.
  */
 public function invoke(PHPUnit_Framework_MockObject_Invocation $invocation)
 {
     foreach ($this->return_map as $entry) {
         if ($entry->matches($invocation)) {
             return $entry->invoke($invocation);
         }
     }
     if ($this->default != NULL) {
         return $this->default->invoke($invocation);
     }
     PHPUnit_Framework_Assert::fail(sprintf('No return value defined for %s', $this->exporter->export($invocation->parameters)));
 }
Exemplo n.º 16
0
 /**
  * Executes a shell command
  *
  * @param $command
  */
 public function runShellCommand($command)
 {
     $data = array();
     exec("{$command}", $data, $resultCode);
     $this->output = implode("\n", $data);
     if ($this->output === null) {
         \PHPUnit_Framework_Assert::fail("{$command} can't be executed");
     }
     if ($resultCode !== 0) {
         \PHPUnit_Framework_Assert::fail("Result code was {$resultCode}.\n\n" . $this->output);
     }
     $this->debug(preg_replace('~s/\\e\\[\\d+(?>(;\\d+)*)m//g~', '', $this->output));
 }
Exemplo n.º 17
0
 /**
  * Запуск консольной symfony команды
  * @param string $command
  * @param bool   $failNonZero
  * @return string
  */
 public function runSymfonyCommand($command, $failNonZero = true)
 {
     $command = sprintf('/kingdom/app/console %s -e test', $command);
     $data = [];
     exec("{$command}", $data, $resultCode);
     $output = implode('\\n', $data);
     if ($output === null) {
         \PHPUnit_Framework_Assert::fail("{$command} can't be executed");
     }
     if ($resultCode !== 0 && $failNonZero) {
         \PHPUnit_Framework_Assert::fail("Result code was {$resultCode}.\n\n" . $output);
     }
     $this->debug(preg_replace('~s/\\e\\[\\d+(?>(;\\d+)*)m//g~', '', $output));
     return $output;
 }
Exemplo n.º 18
0
 public function shouldProduce($name, $msg = null)
 {
     $fn = $this->it;
     try {
         $fn();
         Assert::fail();
     } catch (\Exception $e) {
         if ($name) {
             Assert::assertEquals($name, get_class($e));
         }
         if (!is_null($msg)) {
             Assert::assertEquals($msg, $e->getMessage());
         }
     }
 }
Exemplo n.º 19
0
 public function test()
 {
     $object = new UserDefault();
     $type = UserDefault::class;
     $metadata = new ObjectMetadata($object);
     PHPUnit::assertEquals($type, $metadata->getType());
     PHPUnit::assertNotEquals(10, $object->getId());
     $metadata->setValue($object, 'id', 10);
     PHPUnit::assertEquals(10, $object->getId());
     PHPUnit::assertEquals(new \ReflectionClass($object), $metadata->getReflectionClass());
     try {
         $metadata->getProperty('thisPropertyDoesNotExists', true);
         PHPUnit::fail('Must raise an exception');
     } catch (\RuntimeException $ex) {
     }
     $property = $metadata->getProperty('thisPropertyDoesNotExists');
     PHPUnit::assertNull($property);
     $properties = $metadata->getProperties();
     $type = $metadata->getType();
     $object = unserialize(serialize($metadata));
     PHPUnit::assertEquals($properties, $object->getProperties());
     PHPUnit::assertEquals($type, $object->getType());
     PHPUnit::assertEquals($metadata, $object);
 }
Exemplo n.º 20
0
 /**
  * @Then /^Share fields of last share match with$/
  * @param \Behat\Gherkin\Node\TableNode|null $formData
  */
 public function checkShareFields($body)
 {
     if ($body instanceof \Behat\Gherkin\Node\TableNode) {
         $fd = $body->getRowsHash();
         foreach ($fd as $field => $value) {
             if (!$this->isFieldInResponse($field, $value)) {
                 PHPUnit_Framework_Assert::fail("{$field}" . " doesn't have value " . "{$value}");
             }
         }
     }
 }
Exemplo n.º 21
0
 /**
  * Get the queue/tube URL from the queue name (AWS function only)
  *
  * @param $queue Queue Name
  *
  * @return string Queue URL
  */
 private function getQueueURL($queue)
 {
     $queues = $this->queue->listQueues(array('QueueNamePrefix' => ''))->get('QueueUrls');
     foreach ($queues as $queueURL) {
         $tokens = explode('/', $queueURL);
         if (strtolower($queue) == strtolower($tokens[sizeof($tokens) - 1])) {
             return $queueURL;
         }
     }
     $this->debug('queue: [' . $queue . '] not found');
     \PHPUnit_Framework_Assert::fail('queue [' . $queue . '] not found');
 }
 protected function checkSingleEvent($expected, Event $event, &$eventsByInternalId, &$unmatchedParentEvents)
 {
     /* @var $event NodeEvent */
     $rowId = null;
     foreach ($expected as $rowName => $rowValue) {
         switch ($rowName) {
             case 'ID':
                 if ($rowValue === '') {
                     break;
                 }
                 $rowId = $rowValue;
                 break;
             case 'Parent Event':
                 if ($rowValue === '') {
                     break;
                 }
                 if (isset($eventsByInternalId[$rowValue])) {
                     Assert::assertSame($eventsByInternalId[$rowValue], $event->getParentEvent(), 'Parent event does not match. (1)');
                 } elseif (isset($unmatchedParentEvents[$rowValue]) && $unmatchedParentEvents[$rowValue] !== $event->getParentEvent()) {
                     Assert::fail(sprintf('Parent event "%s" does not match another parent event with the same identifier.', $rowValue));
                 } else {
                     $unmatchedParentEvents[$rowValue] = $event->getParentEvent();
                 }
                 break;
             case 'Event Type':
                 Assert::assertEquals($rowValue, $event->getEventType(), 'Event Type does not match. Expected: ' . $rowValue . '. Actual: ' . $event->getEventType());
                 break;
             case 'Node Identifier':
                 if ($rowValue === '') {
                     break;
                 }
                 Assert::assertEquals($rowValue, $event->getNodeIdentifier(), 'Node Identifier does not match.');
                 break;
             case 'Document Node Identifier':
                 Assert::assertEquals($rowValue, $event->getDocumentNodeIdentifier(), 'Document Node Identifier does not match.');
                 break;
             case 'Workspace':
                 Assert::assertEquals($rowValue, $event->getWorkspaceName(), 'Workspace does not match.');
                 break;
             case 'Explanation':
                 break;
             default:
                 throw new \Exception('Row Name ' . $rowName . ' not supported.');
         }
     }
     if ($rowId !== null) {
         $eventsByInternalId[$rowId] = $event;
         if (isset($unmatchedParentEvents[$rowId])) {
             Assert::assertSame($eventsByInternalId[$rowId], $event, 'Parent event does not match. (2)');
             unset($unmatchedParentEvents[$rowId]);
         }
     }
 }
 /**
  * @Given /^I fail the test$/
  */
 public function iFailTheTest()
 {
     PHPUnit_Framework_Assert::fail('This test has failed');
 }
 public function testNormalizerNotCalledForUnsetOptions()
 {
     $this->resolver->setDefined('norm');
     $this->resolver->setNormalizer('norm', function () {
         \PHPUnit_Framework_Assert::fail('Should not be called.');
     });
     $this->assertEmpty($this->resolver->resolve());
 }
Exemplo n.º 25
0
 /**
  * Fails the test with message.
  *
  * @param $message
  */
 protected function fail($message)
 {
     \PHPUnit_Framework_Assert::fail($message);
 }
Exemplo n.º 26
0
 protected function waitForCommand($command, $arguments, $info)
 {
     for ($second = 0;; $second++) {
         if ($second > $this->httpTimeout) {
             PHPUnit_Framework_Assert::fail('timeout');
         }
         try {
             $this->assertCommand($command, $arguments, $info);
             return;
         } catch (Exception $e) {
         }
         sleep(1);
     }
 }
Exemplo n.º 27
0
 /**
  * Checks if file exists in path.
  * Opens a file when it's exists
  *
  * ``` php
  * <?php
  * $I->seeFileFound('UserModel.php','app/models');
  * ?>
  * ```
  *
  * @param $filename
  * @param string $path
  */
 public function seeFileFound($filename, $path = '')
 {
     $path = $this->absolutizePath($path);
     $this->debug($path);
     if (!file_exists($path)) {
         \PHPUnit_Framework_Assert::fail("Directory does not exist: {$path}");
     }
     $files = \Symfony\Component\Finder\Finder::create()->files()->name($filename)->in($path);
     foreach ($files as $file) {
         $file = $file->getRealPath();
         $this->openFile($file);
         $this->filepath = $file;
         $this->debug($file);
         \PHPUnit_Framework_Assert::assertFileExists($file);
         return;
     }
     \PHPUnit_Framework_Assert::fail("{$filename} in {$path}");
 }
 /**
  * @Given /^I should get (TRUE|FALSE) when asking the node authorization service if setting the "([^"]*)" property is granted$/
  */
 public function iShouldGetFalseWhenAskingTheNodeAuthorizationServiceIfSettingThePropertyIsGranted($expectedResult, $propertyName)
 {
     if ($this->isolated === true) {
         $this->callStepInSubProcess(__METHOD__, sprintf(' %s %s %s %s', 'string', escapeshellarg(trim($expectedResult)), 'string', escapeshellarg($propertyName)));
     } else {
         if ($expectedResult === 'TRUE') {
             if ($this->nodeAuthorizationService->isGrantedToEditNodeProperty($this->currentNodes[0], $propertyName) !== true) {
                 Assert::fail('The node authorization service did not return TRUE!');
             }
         } else {
             if ($this->nodeAuthorizationService->isGrantedToEditNodeProperty($this->currentNodes[0], $propertyName) !== false) {
                 Assert::fail('The node authorization service did not return FALSE!');
             }
         }
     }
 }
Exemplo n.º 29
0
 /**
  * @Given /^group "([^"]*)" does not exist$/
  */
 public function groupDoesNotExist($group)
 {
     try {
         $this->groupExists($group);
         PHPUnit_Framework_Assert::fail('The group "' . $group . '" exists');
     } catch (\GuzzleHttp\Exception\ClientException $ex) {
         $this->response = $ex->getResponse();
         PHPUnit_Framework_Assert::assertEquals(404, $ex->getResponse()->getStatusCode());
     }
 }
Exemplo n.º 30
0
 /**
  * Checks if any email were sent by last request
  *
  * @throws \LogicException
  */
 public function seeEmailIsSent()
 {
     $profile = $this->getProfiler();
     if (!$profile) {
         \PHPUnit_Framework_Assert::fail('Emails can\'t be tested without Profiler');
     }
     if (!$profile->hasCollector('swiftmailer')) {
         \PHPUnit_Framework_Assert::fail('Emails can\'t be tested without SwiftMailer connector');
     }
     \PHPUnit_Framework_Assert::assertGreaterThan(0, $profile->getCollector('swiftmailer')->getMessageCount());
 }