Asserts that a variable is not null.
public static assertNotNull ( mixed $actual, string $message = '' ) | ||
$actual | mixed | |
$message | string |
protected function assertCommonCacheCollectedData(CacheCollectedData $expected, CacheCollectedData $actual) { Assert::assertEquals($expected->getData(), $actual->getData()); Assert::assertNotNull($actual->getDuration()); Assert::assertEquals($expected->getProviderId(), $actual->getProviderId()); Assert::assertEquals($expected->getType(), $actual->getType()); }
public function assertDestinationCorrect(ezcWebdavMemoryBackend $backend) { PHPUnit_Framework_Assert::assertTrue($backend->nodeExists('/other_collection/moved_resource.html')); $prop = $backend->getProperty('/other_collection/moved_resource.html', 'lockdiscovery'); PHPUnit_Framework_Assert::assertNotNull($prop, 'Lock discovery property not available on destination.'); PHPUnit_Framework_Assert::assertEquals(0, count($prop->activeLock), 'Active lock available on destination.'); }
/** * @Given /^I sync (\d+) most recent posts from the category sitemap "([^"]*)"$/ */ public function iSyncMostRecentPostsFromTheCategory($numberOfPosts, $categorySitemap) { $importResponse = Sync::importCategory($categorySitemap, $numberOfPosts); Assert::assertNotNull($importResponse); Assert::assertEquals($numberOfPosts, count($importResponse->posts)); Assert::assertTrue(isset($importResponse->posts[0]->id)); }
public function testPruneOldTransactions() { $tx_helper = app('SampleTransactionsHelper'); $created_txs = []; for ($i = 0; $i < 5; $i++) { $created_txs[] = $tx_helper->createSampleTransaction('sample_xcp_parsed_01.json', ['txid' => str_repeat('0', 63) . ($i + 1)]); } $tx_repository = app('App\\Repositories\\TransactionRepository'); $created_txs[0]->timestamps = false; $tx_repository->update($created_txs[0], ['updated_at' => time() - 60], ['timestamps' => false]); $created_txs[1]->timestamps = false; $tx_repository->update($created_txs[1], ['updated_at' => time() - 59], ['timestamps' => false]); $created_txs[2]->timestamps = false; $tx_repository->update($created_txs[2], ['updated_at' => time() - 5], ['timestamps' => false]); // prune all $this->dispatch(new PruneTransactions(50)); // check that all transactions were erased $tx_repository = app('App\\Repositories\\TransactionRepository'); foreach ($created_txs as $offset => $created_tx) { $loaded_tx = $tx_repository->findByTXID($created_tx['txid']); if ($offset < 2) { PHPUnit::assertNull($loaded_tx, "found unexpected tx: " . ($loaded_tx ? json_encode($loaded_tx->toArray(), 192) : 'null')); } else { PHPUnit::assertNotNull($loaded_tx, "missing tx {$offset}"); PHPUnit::assertEquals($created_tx->toArray(), $loaded_tx->toArray()); } } }
/** * @inheritdoc */ public function assertDataPersisted($name, array $data) { $alias = $this->convertNameToAlias($this->singularize($name)); $class = $this->getEntityManager()->getClassMetadata($alias)->getName(); $found = []; foreach ($data as $row) { $criteria = $this->applyMapping($this->getFieldMapping($class), $row); $criteria = $this->rowToEntityData($class, $criteria, false); $jsonArrayFields = $this->getJsonArrayFields($class, $criteria); $criteria = array_diff_key($criteria, $jsonArrayFields); $entity = $this->getEntityManager()->getRepository($class)->findOneBy($criteria); Assert::assertNotNull($entity, sprintf('The repository should find data of type "%s" with these criteria: %s', $alias, json_encode($criteria))); if (!empty($jsonArrayFields)) { // refresh json fields as they may have changed beforehand $this->getEntityManager()->refresh($entity); // json array fields can not be matched by the ORM (depends on driver and requires driver-specific operators), // therefore we need to check these separately $accessor = PropertyAccess::createPropertyAccessor(); foreach ($jsonArrayFields as $field => $value) { Assert::assertSame($value, $accessor->getValue($entity, $field)); } } $found[] = $entity; } return $found; }
public function assertTargetStillLocked(ezcWebdavMemoryBackend $backend) { $prop = $backend->getProperty('/collection/resource.html', 'lockdiscovery'); PHPUnit_Framework_Assert::assertNotNull($prop, 'Lock discovery property removed from target.'); PHPUnit_Framework_Assert::assertEquals(1, count($prop->activeLock), 'Target parent active lock gone.'); PHPUnit_Framework_Assert::assertEquals('opaquelocktoken:1234', $prop->activeLock[0]->token->__toString()); }
protected function __construct($server_url, $capabilities) { $this->server_url = $server_url; $this->browser = $capabilities['browserName']; $payload = array("desiredCapabilities" => $capabilities); $response = $this->execute("POST", "/session", $payload); // Parse out session id for Selenium <= 2.33.0 $matches = array(); preg_match("/Location:.*\\/(.*)/", $response['header'], $matches); if (count($matches) === 2) { $this->session_id = trim($matches[1]); } if (!$this->session_id) { // Starting with Selenium 2.34.0, the session id is in the body instead if (isset($response['body'])) { $capabilities = json_decode(trim($response['body']), true); if ($capabilities !== null && isset($capabilities['sessionId'])) { $this->session_id = $capabilities['sessionId']; } } } if (!$this->session_id) { // The Chrome driver returns the session id in the value array $this->session_id = WebDriver::GetJSONValue($response, "webdriver.remote.sessionid"); } PHPUnit_Framework_Assert::assertNotNull($this->session_id, "Did not get a session id from {$server_url}\n" . print_r($response, true)); }
public function assertLockDiscoveryPropertyCorrect(ezcWebdavMemoryBackend $backend) { $prop = $backend->getProperty('/collection/newresource.xml', 'lockdiscovery'); PHPUnit_Framework_Assert::assertNotNull($prop, 'Lock discovery property not set.'); PHPUnit_Framework_Assert::assertType('ezcWebdavLockDiscoveryProperty', $prop, 'Lock discovery property has incorrect type.'); PHPUnit_Framework_Assert::assertEquals(1, count($prop->activeLock), 'Number of activeLock elements incorrect.'); PHPUnit_Framework_Assert::assertEquals(new ezcWebdavPotentialUriContent('http://example.com/some/user', true), $prop->activeLock[0]->owner, 'Lock owner not correct.'); }
public function assertDestinationCorrect(ezcWebdavMemoryBackend $backend) { PHPUnit_Framework_Assert::assertTrue($backend->nodeExists('/other_collection/moved_resource.html')); $prop = $backend->getProperty('/other_collection/moved_resource.html', 'lockdiscovery'); PHPUnit_Framework_Assert::assertNotNull($prop, 'Lock discovery property not available on destination.'); PHPUnit_Framework_Assert::assertType('ezcWebdavLockDiscoveryProperty', $prop); PHPUnit_Framework_Assert::assertEquals(1, count($prop->activeLock), 'Active lock element not available on destination.'); PHPUnit_Framework_Assert::assertEquals('opaquelocktoken:5678', $prop->activeLock[0]->token->__toString(), 'Active lock token on destination incorrect.'); }
/** * Проверка наличия предмета в инвентаре * @param string $itemId * @return InventoryItem */ public function haveItem($itemId) { $symfonyModule = $this->getSymfonyModule(); $user = $this->getUser($symfonyModule); $itemRepository = $symfonyModule->container->get('kingdom.inventory_item_repository'); $item = $itemRepository->findOneByUserAndItemId($user, $itemId); \PHPUnit_Framework_Assert::assertNotNull($item); return $item; }
protected function _enterEmailAddress($email) { $id = 'check-email'; $input = $this->getSession()->getPage()->find('xpath', '//*[@id="' . $id . '"]'); \PHPUnit_Framework_Assert::assertNotNull($input); $this->getSession()->getPage()->fillField($id, $email); $this->getSession()->getDriver()->click('//button[@onclick="checkEmail(this);"]'); sleep(2); }
public function assertDestinationSourceStillCorrect(ezcWebdavMemoryBackend $backend) { $prop = $backend->getProperty('/collection', 'lockdiscovery'); PHPUnit_Framework_Assert::assertNotNull($prop, 'Lock discovery property set on source parent.'); PHPUnit_Framework_Assert::assertEquals(1, count($prop->activeLock), 'Active lock available not on source parent.'); $prop = $backend->getProperty('/collection/resource.html', 'lockdiscovery'); PHPUnit_Framework_Assert::assertNotNull($prop, 'Lock discovery property set on source.'); PHPUnit_Framework_Assert::assertEquals(1, count($prop->activeLock), 'Active lock available not on source.'); }
public function testAPI() { $api = new RippleAPI(new Connection()); $index = $api->currentLedgerIndex(); PHPUnit::assertNotNull($index); PHPUnit::assertGreaterThan(6000000, $index); $index = $api->currentLedgerIndex(); PHPUnit::assertNotNull($index); PHPUnit::assertGreaterThan(6000000, $index); }
public function testCreateAndSave() { $directory = new FooDirectory($this->getMongoDB()); $model = $directory->create([]); $model['added1'] = 'yes'; $model = $directory->save($model); PHPUnit::assertNotNull($model['_id']); $model = $directory->reload($model); PHPUnit::assertEquals('yes', $model['added1']); }
/** * Checks if the document has link that contains specified * text (or text and url) * * @param string $text * @param string $url (Default: null) * @return mixed */ public function seeLink($text, $url = null) { $text = $this->escape($text); $nodes = $this->session->getPage()->findAll('named', array('link', $this->session->getSelectorsHandler()->xpathLiteral($text))); if (!$url) { return \PHPUnit_Framework_Assert::assertNotNull($nodes); } foreach ($nodes as $node) { if (false !== strpos($node->getAttribute('href'), $url)) { return \PHPUnit_Framework_Assert::assertContains($text, $node->getHtml(), "with url '{$url}'"); } } return \PHPUnit_Framework_Assert::fail("with url '{$url}'"); }
/** * @Then /^I see following packages for version "([^"]*)" imported(?:|\:)$/ */ public function iSeeFollowingPackagesForVersionImported($version, TableNode $packagesTable) { $packages = $this->getSubContext('Common')->convertTableToArrayOfData($packagesTable); foreach ($packages as $packageName) { // this can't use the self::iSeeImported() since the versions don't // have a space between "ver." and the actual version $versionLabel = "{$packageName} (ver.{$version})"; // notice this xpath uses contains instead of the "=" because the // text as an <enter> and trailing spaces, so it fails $el = $this->getSession()->getPage()->find("xpath", "//*[contains( text(), '{$versionLabel}' )]"); Assertion::assertNotNull($el, "Couldn't find '{$versionLabel}' package"); $importElement = $this->findElementAfterElement($this->findRow($el)->findAll("xpath", "td"), "../*[contains( text(), '{$versionLabel}' )]", "//*[text() = 'Imported']"); Assertion::assertNotNull($importElement, "Couldn't find 'Imported' for '{$versionLabel}' package"); } }
/** * @Given a cookie named :name should have been added to the response with a lifetime of :lifetimeCount :lifetimePeriod */ public function aCookieNamedShouldHaveBeenAddedToTheResponseWithALifeTimeOf($name, $lifetimeCount, $lifetimePeriod) { $driver = $this->getSession()->getDriver(); if (!$driver instanceof BrowserKitDriver) { throw new UnsupportedDriverActionException('This step is only supported by the BrowserKitDriver', $driver); } $cookie = $driver->getClient()->getCookieJar()->get($name); Assert::assertNotNull($cookie, sprintf('A cookie should have been made named %s', $name)); $lifetime = $lifetimeCount . ' ' . $lifetimePeriod; $expectedExpiresTime = strtotime($lifetime); $actualExpiresTime = $cookie->getExpiresTime(); // allow few seconds of difference due to time spent testing $matches = $actualExpiresTime > $expectedExpiresTime - 5 && $actualExpiresTime <= $expectedExpiresTime; Assert::assertTrue($matches, sprintf('The cookie should expire between %s and %s', $expectedExpiresTime - 5, $expectedExpiresTime)); }
/** * @When I create an expense list named :name */ public function iCreateAnExpenseListNamed($name) { $json = <<<JSON { "name": "{$name}" } JSON; $this->client->request('POST', '/expense_list/', [], [], ['CONTENT_TYPE' => 'application/json'], $json); $response = $this->client->getResponse(); PHPUnit_Framework_Assert::assertEquals(Response::HTTP_CREATED, $response->getStatusCode()); PHPUnit_Framework_Assert::assertJson($response->getContent()); $responseData = json_decode($response->getContent()); PHPUnit_Framework_Assert::assertNotNull($responseData); PHPUnit_Framework_Assert::assertObjectHasAttribute('id', $responseData); $this->expenseListId = $responseData->id; }
public function testIndividisbleXCPEvent() { $transactions = $this->buildTransactionsHelper(); // listen for fired event $heard_tx_data = null; $this->app->make('events')->listen('xchain.tx.received', function ($tx_data) use(&$heard_tx_data) { $heard_tx_data = $tx_data; }); $data = $transactions->formatTxAsXstalkerJobData($transactions->getSampleTopFolderCounterpartyTransaction()); $this->buildBTCTransactionJob()->fire($this->getQueueJob(), $data); // validate tx data PHPUnit::assertNotNull($heard_tx_data); PHPUnit::assertEquals(['1NVddDzRUvn8bHZEG9n5W7gfMTLeBeNAHQ'], $heard_tx_data['sources']); PHPUnit::assertEquals(['16cES2Nxv9D5vjsMT5A4HEwhbUPDg3Nnpd'], $heard_tx_data['destinations']); PHPUnit::assertEquals(['16cES2Nxv9D5vjsMT5A4HEwhbUPDg3Nnpd' => 100], $heard_tx_data['values']); }
public function testPruneOldBlocks() { $block_helper = app('SampleBlockHelper'); $created_blocks = []; for ($i = 0; $i < 5; $i++) { $created_blocks[] = $block_helper->createSampleBlock('default_parsed_block_01.json', ['hash' => str_repeat('0', 63) . ($i + 1), 'height' => 10001 + $i]); } // prune last 3 $this->dispatch(new PruneBlocks(3)); $block_repository = app('App\\Repositories\\BlockRepository'); foreach ($created_blocks as $offset => $created_block) { $loaded_block = $block_repository->findByHash($created_block['hash']); if ($offset < 2) { PHPUnit::assertNull($loaded_block, "found unexpected block: " . ($loaded_block ? json_encode($loaded_block->toArray(), 192) : 'null')); } else { PHPUnit::assertNotNull($loaded_block, "missing block {$offset}"); PHPUnit::assertEquals($created_block->toArray(), $loaded_block->toArray()); } } }
/** * Find field element * This is a complement to the normal search, because in some cases the * label has no "for" attribute, so the normal search won't find it. So this * will try to find an input right after a label with $field * * @param string $field Can be id, name, label, value * * @return \Behat\Mink\Element\NodeElement */ protected function findFieldElement($field) { $page = $this->getSession()->getPage(); // attempt to find field through id, name, or label $fieldElement = $page->findField($field); if (empty($fieldElement)) { // if field wasn't found, and there is an label for that, we will // attempt to find the next input after the label $fieldElement = $page->find("xpath", "//*[self::" . implode(" or self::", $this->getTagsFor('input')) . "][preceding::label[contains( text(), " . $this->getXpath()->literal($field) . " )]]"); } Assertion::assertNotNull($fieldElement, "Couldn't find '{$field}' field"); return $fieldElement; }
/** * Asserts that a variable is not NULL. * * @param mixed $actual * @param string $message */ function assertNotNull($actual, $message = '') { return PHPUnit_Framework_Assert::assertNotNull($actual, $message); }
/** * Checks weather last response was valid XMLRPC. * This is done with xmlrpc_decode function. * */ public function seeResponseIsXMLRPC() { $result = xmlrpc_decode($this->response); \PHPUnit_Framework_Assert::assertNotNull($result, 'Invalid response document returned from XmlRpc server'); }
/** * @Given /^that there is a siteaccess that is not the default one$/ */ public function thereIsASiteaccessThatIsNotTheDefaultOne() { $siteaccessName = $this->getNonDefaultSiteaccessName(); Assertion::assertNotNull($siteaccessName, 'There is no siteaccess other than the default one'); $this->it['siteaccess'] = $siteaccessName; }
/** * Checks that variable is not NULL * * @param $actual * @param string $message */ protected function assertNotNull($actual, $message = '') { \PHPUnit_Framework_Assert::assertNotNull($actual, $message); }
/** * @depends testGetAllSettings */ public function testSettingDomains() { // Create Parent Child Settings $parentSetting = array('domain' => "ParentDomain", 'settingKey' => 'ParentKey', 'value' => 'ChildDomain', 'type' => 'text', 'parent' => null); $ret = self::$pdo->create($parentSetting); PHPUnit_Framework_Assert::assertNotNull($ret); PHPUnit_Framework_Assert::assertEquals($ret['value'], 'ChildDomain'); $childSetting = array('domain' => "ChildDomain", 'type' => 'text', 'parent' => 'ParentDomain'); $childCount = 10; for ($i = 1; $i <= $childCount; $i++) { $childSetting['settingKey'] = 'ChildKey.' . $i; $childSetting['value'] = 'ChildValue.' . $i; $ret = self::$pdo->create($childSetting); PHPUnit_Framework_Assert::assertNotNull($ret); } // All Settings $settings = self::$pdo->getAll(); PHPUnit_Framework_Assert::assertGreaterThan($childCount, count($settings)); PHPUnit_Framework_Assert::assertNotNull($settings[0]['domain']); // fwrite(STDERR, print_r('Number of settings: '.count($settings)."\n", // TRUE)); // All Settings For One Domain $settings = self::$pdo->getAllDomain('ChildDomain'); PHPUnit_Framework_Assert::assertEquals($childCount, count($settings)); PHPUnit_Framework_Assert::assertNotNull($settings[0]['domain']); // fwrite(STDERR, print_r('Domain for first setting: // '.$settings[0]['domain']."\n", TRUE)); // fwrite(STDERR, print_r('Setting for first setting: // '.$settings[0]['setting']."\n", TRUE)); // fwrite(STDERR, print_r('Value for first setting: // '.$settings[0]['value']."\n", TRUE)); // Domain List $domains = self::$pdo->getDomains(); PHPUnit_Framework_Assert::assertGreaterThan(2, count($domains)); PHPUnit_Framework_Assert::assertNotNull($domains[0]); // Delete all settings for specified domain self::$pdo->deleteAllDomain('ChildDomain'); $settings = self::$pdo->getAllDomain('ChildDomain'); PHPUnit_Framework_Assert::assertEquals(0, count($settings)); self::$pdo->deleteAllDomain('ParentDomain'); $settings = self::$pdo->getAllDomain('ParentDomain'); PHPUnit_Framework_Assert::assertEquals(0, count($settings)); }
public function assertTargetPropertySet(ezcWebdavMemoryBackend $backend) { $prop = $backend->getProperty('/collection/resource.html', 'authors', 'http://www.w3.com/standards/z39.50/'); PHPUnit_Framework_Assert::assertNotNull($prop, 'Desired property not set.'); }
public static function GetJSONValue($curl_response, $attribute = null) { PHPUnit_Framework_Assert::assertArrayHasKey('body', $curl_response, "Response had no body\n{$curl_response['header']}"); $array = json_decode(trim($curl_response['body']), true); PHPUnit_Framework_Assert::assertNotNull($array, "Body could not be decoded as JSON\n{$curl_response['body']}"); PHPUnit_Framework_Assert::assertArrayHasKey('value', $array, "JSON had no value\n" . print_r($array, true)); if ($attribute === null) { $rv = $array["value"]; } else { if (isset($array["value"][$attribute])) { $rv = $array["value"][$attribute]; } else { if (is_array($array["value"])) { $rv = array(); foreach ($array["value"] as $a_value) { PHPUnit_Framework_Assert::assertArrayHasKey($attribute, $a_value, "JSON value did not have attribute {$attribute}\n" . print_r($array, true)); $rv[] = $a_value[$attribute]; } } } PHPUnit_Framework_Assert::assertNotNull($rv, "JSON value did not have attribute {$attribute}\n" . print_r($array["value"], true)); } return $rv; }
/** * @Then on :pageSection I (should) see the exact :text message/text * * @deprecated deprecated since version 6.3.0 */ public function onPageSectionISeeText($text, $pageSection = null) { trigger_error("onPageSectionISeeText is deprecated since v6.3.0 and will be removed in v7.0.0", E_USER_DEPRECATED); $base = $this->makeXpathForBlock($pageSection); $literal = $this->getXpath()->literal($text); $el = $this->getXpath()->findXpath("{$base}//*[contains( text(), {$literal} )]"); Assertion::assertNotNull($el, "Couldn't find '{$text}' text"); Assertion::assertEquals(trim($el->getText()), $text, "Couldn't find '{$text}' text"); }
/** * @return NodeElement */ public function findPager() { \PHPUnit_Framework_Assert::assertNotNull($pager = $this->getPager(), 'The pager could not be found.'); return $pager; }