assertCount() public static method

Asserts the number of elements of an array, Countable or Traversable.
public static assertCount ( integer $expectedCount, mixed $haystack, string $message = '' )
$expectedCount integer
$haystack mixed
$message string
 /**
  * @param CacheCollectedData[] $expectedCollectedData
  * @param CacheCollectedData[] $actualCollectedData
  */
 protected function assertCacheCollectedData(array $expectedCollectedData, array $actualCollectedData)
 {
     Assert::assertCount(count($expectedCollectedData), $actualCollectedData);
     foreach ($expectedCollectedData as $key => $expectedItem) {
         $this->assertSingleCacheCollectedData($expectedItem, $actualCollectedData[$key]);
     }
 }
Beispiel #2
0
 /**
  * @param int      $expectedType     Expected triggered error type (pass one of PHP's E_* constants)
  * @param string[] $expectedMessages Expected error messages
  * @param callable $testCode         A callable that is expected to trigger the error messages
  */
 public static function assertErrorsAreTriggered($expectedType, $expectedMessages, $testCode)
 {
     if (!is_callable($testCode)) {
         throw new \InvalidArgumentException(sprintf('The code to be tested must be a valid callable ("%s" given).', gettype($testCode)));
     }
     $e = null;
     $triggeredMessages = array();
     try {
         $prevHandler = set_error_handler(function ($type, $message, $file, $line, $context) use($expectedType, &$triggeredMessages, &$prevHandler) {
             if ($expectedType !== $type) {
                 return null !== $prevHandler && call_user_func($prevHandler, $type, $message, $file, $line, $context);
             }
             $triggeredMessages[] = $message;
         });
         call_user_func($testCode);
     } catch (\Exception $e) {
     } catch (\Throwable $e) {
     }
     restore_error_handler();
     if (null !== $e) {
         throw $e;
     }
     \PHPUnit_Framework_Assert::assertCount(count($expectedMessages), $triggeredMessages);
     foreach ($triggeredMessages as $i => $message) {
         \PHPUnit_Framework_Assert::assertContains($expectedMessages[$i], $message);
     }
 }
 public function testProcess()
 {
     if (!class_exists(TransactionMiddleware::class)) {
         $this->markTestSkipped('"league/tactician-doctrine" is not installed');
     }
     $this->container->shouldReceive('hasParameter')->with('doctrine.entity_managers')->once()->andReturn(true);
     $this->container->shouldReceive('getParameter')->with('doctrine.entity_managers')->once()->andReturn(['default' => 'doctrine.orm.default_entity_manager', 'second' => 'doctrine.orm.second_entity_manager']);
     $this->container->shouldReceive('getParameter')->with('doctrine.default_entity_manager')->once()->andReturn('default');
     $this->container->shouldReceive('setDefinition')->andReturnUsing(function ($name, Definition $def) {
         \PHPUnit_Framework_Assert::assertEquals('tactician.middleware.doctrine.default', $name);
         \PHPUnit_Framework_Assert::assertEquals(TransactionMiddleware::class, $def->getClass());
         \PHPUnit_Framework_Assert::assertCount(1, $def->getArguments());
         \PHPUnit_Framework_Assert::assertInstanceOf(Reference::class, $def->getArgument(0));
         \PHPUnit_Framework_Assert::assertEquals('doctrine.orm.default_entity_manager', (string) $def->getArgument(0));
     })->once();
     $this->container->shouldReceive('setDefinition')->andReturnUsing(function ($name, Definition $def) {
         \PHPUnit_Framework_Assert::assertEquals('tactician.middleware.doctrine.second', $name);
         \PHPUnit_Framework_Assert::assertEquals(TransactionMiddleware::class, $def->getClass());
         \PHPUnit_Framework_Assert::assertCount(1, $def->getArguments());
         \PHPUnit_Framework_Assert::assertInstanceOf(Reference::class, $def->getArgument(0));
         \PHPUnit_Framework_Assert::assertEquals('doctrine.orm.second_entity_manager', (string) $def->getArgument(0));
     })->once();
     $this->container->shouldReceive('setDefinition')->with('tactician.middleware.doctrine.second')->once();
     $this->container->shouldReceive('setAlias')->once()->with('tactician.middleware.doctrine', 'tactician.middleware.doctrine.default');
     $this->compiler->process($this->container);
 }
Beispiel #4
0
 public function testMultiplePaymentAddressSendsWithSameClientGUID()
 {
     // mock the xcp sender
     $mock_calls = app('CounterpartySenderMockBuilder')->installMockCounterpartySenderDependencies($this->app, $this);
     $user = app('\\UserHelper')->createSampleUser();
     $payment_address = app('\\PaymentAddressHelper')->createSamplePaymentAddress($user);
     // create a send with a client guid
     $api_tester = $this->getAPITester();
     $posted_vars = $this->sendHelper()->samplePostVars();
     $posted_vars['requestId'] = 'request001';
     $expected_created_resource = ['id' => '{{response.id}}', 'destination' => '{{response.destination}}', 'destinations' => '', 'asset' => 'TOKENLY', 'sweep' => '{{response.sweep}}', 'quantity' => '{{response.quantity}}', 'txid' => '{{response.txid}}', 'requestId' => 'request001'];
     $loaded_resource_model = $api_tester->testAddResource($posted_vars, $expected_created_resource, $payment_address['uuid']);
     // get_asset_info followed by the send
     PHPUnit::assertCount(1, $mock_calls['btcd']);
     // validate that a mock send was triggered
     $send_details = app('TransactionComposerHelper')->parseCounterpartyTransaction($mock_calls['btcd'][0]['args'][0]);
     PHPUnit::assertEquals('1JztLWos5K7LsqW5E78EASgiVBaCe6f7cD', $send_details['destination']);
     PHPUnit::assertEquals(CurrencyUtil::valueToSatoshis(100), $send_details['quantity']);
     PHPUnit::assertEquals('TOKENLY', $send_details['asset']);
     // try the send again with the same request_id
     $expected_resource = $loaded_resource_model;
     $posted_vars = $this->sendHelper()->samplePostVars();
     $posted_vars['requestId'] = 'request001';
     $loaded_resource_model_2 = $api_tester->testAddResource($posted_vars, $expected_created_resource, $payment_address['uuid']);
     // does not send again
     PHPUnit::assertCount(1, $mock_calls['btcd']);
     // second send resource is the same as the first
     PHPUnit::assertEquals($loaded_resource_model, $loaded_resource_model_2);
 }
Beispiel #5
0
 public function testInitialFindMissingBlocks()
 {
     // init mocks
     app('CounterpartySenderMockBuilder')->installMockCounterpartySenderDependencies($this->app, $this);
     $blockchain_store = $this->app->make('App\\Blockchain\\Block\\BlockChainStore');
     $block_events = $blockchain_store->loadMissingBlockEventsFromBitcoind('BLOCKHASH04');
     PHPUnit::assertCount(1, $block_events);
 }
 function assertions($array, $count = 1)
 {
     PHPUnit_Framework_Assert::assertCount($count, $array);
     PHPUnit_Framework_Assert::assertTrue($array['foo'] === 'bar');
     PHPUnit_Framework_Assert::assertTrue($array['Foo'] === 'bar');
     PHPUnit_Framework_Assert::assertTrue($array['FOo'] === 'bar');
     PHPUnit_Framework_Assert::assertTrue($array['FOO'] === 'bar');
 }
 /** @test */
 public function it_can_be_added_to_faker_as_a_provider_and_used()
 {
     $faker = Factory::create();
     $faker->addProvider(new BuzzwordJobProvider($faker));
     $jobTitle = $faker->jobTitle();
     $jobTitleWords = explode(' ', $jobTitle);
     Assert::assertCount(3, $jobTitleWords);
 }
 function assertions($array, $count = 1)
 {
     PHPUnit_Framework_Assert::assertCount($count, $array);
     PHPUnit_Framework_Assert::assertEquals('bar', $array['foo']);
     PHPUnit_Framework_Assert::assertEquals('bar', $array['Foo']);
     PHPUnit_Framework_Assert::assertEquals('bar', $array['FOo']);
     PHPUnit_Framework_Assert::assertEquals('bar', $array['FOO']);
 }
 /**
  * Assert that first item in grid is not the same on ascending and descending sorting
  *
  * @param array $results
  */
 public function processAssert(array $results)
 {
     foreach ($results as $itemId => $ids) {
         \PHPUnit_Framework_Assert::assertCount(1, $ids, sprintf('Full text search should find only %s item. Following items displayed: %s', $itemId, implode(', ', $ids)));
         $actualItemId = $ids[0];
         \PHPUnit_Framework_Assert::assertEquals($itemId, $actualItemId, sprintf('%d item is displayed instead of %d after full text search', $actualItemId, $itemId));
     }
 }
 /**
  * Assert that first item in grid is not the same on ascending and descending sorting
  *
  * @param array $filterResults
  */
 public function processAssert(array $filterResults)
 {
     foreach ($filterResults as $itemId => $filters) {
         foreach ($filters as $filterName => $ids) {
             \PHPUnit_Framework_Assert::assertCount(1, $ids, sprintf('Filtering by "%s" should result in only item id "%d" displayed. %s items ids present', $itemId, $filterName, implode(', ', $ids)));
             $actualItemId = $ids[0];
             \PHPUnit_Framework_Assert::assertEquals($itemId, $actualItemId, sprintf('%d item is displayed instead of %d after applying "%s" filter', $actualItemId, $itemId, $filterName));
         }
     }
 }
Beispiel #11
0
 /**
  * @Then /^the console output should have lines ending in:$/
  */
 public function theConsoleOutputShouldHaveLinesEndingIn(PyStringNode $string)
 {
     $stdOutLines = explode(PHP_EOL, $this->lastBehatStdOut);
     $expectedLines = $string->getLines();
     \PHPUnit_Framework_Assert::assertCount(count($expectedLines), $stdOutLines);
     foreach ($stdOutLines as $idx => $stdOutLine) {
         $suffix = isset($expectedLines[$idx]) ? $expectedLines[$idx] : '(NONE)';
         $constraint = \PHPUnit_Framework_Assert::stringEndsWith($suffix);
         $constraint->evaluate($stdOutLine);
     }
 }
 public function testAPIGetBalances()
 {
     // sample user for Auth
     $sample_user = app('UserHelper')->createSampleUser();
     $address = app('PaymentAddressHelper')->createSamplePaymentAddressWithoutDefaultAccount($sample_user);
     // add noise
     $sample_user_2 = app('UserHelper')->newRandomUser();
     $address_2 = app('PaymentAddressHelper')->createSamplePaymentAddressWithoutDefaultAccount($sample_user_2);
     app('AccountHelper')->newSampleAccount($address_2);
     app('AccountHelper')->newSampleAccount($address_2, 'address 2');
     // create 2 models
     $api_test_helper = $this->getAPITestHelper($address);
     $created_accounts = [];
     $created_accounts[] = $api_test_helper->newModel();
     $created_accounts[] = $api_test_helper->newModel();
     $inactive_account = app('AccountHelper')->newSampleAccount($address, ['name' => 'Inactive 1', 'active' => 0]);
     // add balances to each
     $txid = 'deadbeef00000000000000000000000000000000000000000000000000000001';
     $repo = app('App\\Repositories\\LedgerEntryRepository');
     $repo->addCredit(11, 'BTC', $created_accounts[0], LedgerEntry::CONFIRMED, LedgerEntry::DIRECTION_RECEIVE, $txid);
     $repo->addCredit(20, 'BTC', $created_accounts[1], LedgerEntry::CONFIRMED, LedgerEntry::DIRECTION_RECEIVE, $txid);
     $repo->addDebit(1, 'BTC', $created_accounts[0], LedgerEntry::CONFIRMED, LedgerEntry::DIRECTION_RECEIVE, $txid);
     $repo->addCredit(4, 'BTC', $created_accounts[0], LedgerEntry::UNCONFIRMED, LedgerEntry::DIRECTION_RECEIVE, $txid);
     $repo->addCredit(5, 'BTC', $created_accounts[1], LedgerEntry::UNCONFIRMED, LedgerEntry::DIRECTION_RECEIVE, $txid);
     // now get all the accounts
     $api_response = $api_test_helper->callAPIAndValidateResponse('GET', '/api/v1/accounts/balances/' . $address['uuid'] . '');
     PHPUnit::assertCount(2, $api_response);
     PHPUnit::assertEquals($created_accounts[0]['uuid'], $api_response[0]['id']);
     // check balances
     PHPUnit::assertEquals(['BTC' => 10], $api_response[0]['balances']['confirmed']);
     PHPUnit::assertEquals(['BTC' => 20], $api_response[1]['balances']['confirmed']);
     PHPUnit::assertEquals(['BTC' => 4], $api_response[0]['balances']['unconfirmed']);
     PHPUnit::assertEquals(['BTC' => 5], $api_response[1]['balances']['unconfirmed']);
     // get by name
     $api_response = $api_test_helper->callAPIAndValidateResponse('GET', '/api/v1/accounts/balances/' . $address['uuid'] . '?name=Address 1');
     PHPUnit::assertCount(1, $api_response);
     PHPUnit::assertEquals($created_accounts[0]['uuid'], $api_response[0]['id']);
     PHPUnit::assertEquals(['BTC' => 10], $api_response[0]['balances']['confirmed']);
     // get inactive
     $api_response = $api_test_helper->callAPIAndValidateResponse('GET', '/api/v1/accounts/balances/' . $address['uuid'] . '?active=false');
     PHPUnit::assertCount(1, $api_response);
     PHPUnit::assertEquals($inactive_account['uuid'], $api_response[0]['id']);
     // get by type
     $api_response = $api_test_helper->callAPIAndValidateResponse('GET', '/api/v1/accounts/balances/' . $address['uuid'] . '?type=unconfirmed');
     PHPUnit::assertCount(2, $api_response);
     PHPUnit::assertEquals(['BTC' => 4], $api_response[0]['balances']);
     PHPUnit::assertEquals(['BTC' => 5], $api_response[1]['balances']);
     $api_response = $api_test_helper->callAPIAndValidateResponse('GET', '/api/v1/accounts/balances/' . $address['uuid'] . '?type=confirmed');
     PHPUnit::assertCount(2, $api_response);
     PHPUnit::assertEquals(['BTC' => 10], $api_response[0]['balances']);
     PHPUnit::assertEquals(['BTC' => 20], $api_response[1]['balances']);
 }
Beispiel #13
0
 public function testFindUserWithWebhookEndpoint()
 {
     // insert
     $user_repo = $this->app->make('App\\Repositories\\UserRepository');
     $created_user_model = $user_repo->create($this->app->make('\\UserHelper')->sampleDBVars());
     // load from repo
     $users = $user_repo->findWithWebhookEndpoint();
     PHPUnit::assertNotEmpty($users);
     PHPUnit::assertCount(1, $users);
     foreach ($users as $user) {
         break;
     }
     PHPUnit::assertEquals('TESTAPITOKEN', $user['apitoken']);
 }
 /**
  * @Then /^the database should contain (\d+) "([^"]*)" entities$/
  */
 public function thereShouldBeEntities($nbr, $class)
 {
     switch ($class) {
         case 'dummy':
             $repository = $this->entityManager->getRepository('TestBundle:Dummy');
             break;
         case 'another_dummy':
             $repository = $this->entityManager->getRepository('TestBundle:AnotherDummy');
             break;
         default:
             throw new \UnexpectedValueException(sprintf('Unknown %s entity', $class));
     }
     PHPUnit::assertCount((int) $nbr, $repository->findAll());
 }
Beispiel #15
0
 public function testFindMissingBlocks()
 {
     // init mocks
     app('CounterpartySenderMockBuilder')->installMockCounterpartySenderDependencies($this->app, $this);
     // insert
     $created_block_model_1 = $this->blockHelper()->createSampleBlock('default_parsed_block_01.json', ['hash' => 'BLOCKHASH01BASE01', 'height' => 333000, 'parsed_block' => ['height' => 333000]]);
     $created_block_model_2 = $this->blockHelper()->createSampleBlock('default_parsed_block_01.json', ['hash' => 'BLOCKHASH02', 'previousblockhash' => 'BLOCKHASH01BASE01', 'height' => 333001, 'parsed_block' => ['height' => 333001]]);
     // MISSING BLOCKHASH03 and BLOCKHASH04
     $created_block_model_3 = $this->blockHelper()->createSampleBlock('default_parsed_block_01.json', ['hash' => 'BLOCKHASH05', 'previousblockhash' => 'BLOCKHASH04', 'height' => 333004, 'parsed_block' => ['height' => 333004]]);
     $blockchain_store = $this->app->make('App\\Blockchain\\Block\\BlockChainStore');
     $block_events = $blockchain_store->loadMissingBlockEventsFromBitcoind('BLOCKHASH04', 4);
     PHPUnit::assertCount(2, $block_events);
     // make sure they were loaded in the correct order
     PHPUnit::assertEquals(['BLOCKHASH03', 'BLOCKHASH04'], [$block_events[0]['hash'], $block_events[1]['hash']]);
 }
 public function testFindAllTransactionsConfirmedInBlockHashes()
 {
     // insert
     $created_transaction_models = [];
     $created_transaction_models[] = $this->txHelper()->createSampleTransaction('sample_xcp_parsed_01.json', ['txid' => 'TX01', 'bitcoinTx' => ['blockhash' => 'BLOCKHASH01']]);
     $created_transaction_models[] = $this->txHelper()->createSampleTransaction('sample_xcp_parsed_01.json', ['txid' => 'TX02', 'bitcoinTx' => ['blockhash' => 'BLOCKHASH02']]);
     $created_transaction_models[] = $this->txHelper()->createSampleTransaction('sample_xcp_parsed_01.json', ['txid' => 'TX03', 'bitcoinTx' => ['blockhash' => 'BLOCKHASH03']]);
     // load from repo
     $tx_repo = $this->app->make('App\\Repositories\\TransactionRepository');
     $loaded_transaction_models = $tx_repo->findAllTransactionsConfirmedInBlockHashes(['BLOCKHASH02', 'BLOCKHASH03']);
     PHPUnit::assertNotEmpty($loaded_transaction_models);
     PHPUnit::assertCount(2, $loaded_transaction_models);
     PHPUnit::assertEquals('TX02', $loaded_transaction_models[0]['txid']);
     PHPUnit::assertEquals('TX03', $loaded_transaction_models[1]['txid']);
 }
 public function testAddCreditsAndDebits()
 {
     $helper = $this->createRepositoryTestHelper();
     $helper->cleanup();
     $account = app('AccountHelper')->newSampleAccount();
     $txid = 'deadbeef00000000000000000000000000000000000000000000000000000001';
     // add credit
     $repo = app('App\\Repositories\\LedgerEntryRepository');
     $repo->addCredit(100, 'BTC', $account, LedgerEntry::CONFIRMED, LedgerEntry::DIRECTION_OTHER, $txid);
     $repo->addCredit(200, 'BTC', $account, LedgerEntry::CONFIRMED, LedgerEntry::DIRECTION_OTHER, $txid);
     $repo->addDebit(300, 'BTC', $account, LedgerEntry::CONFIRMED, LedgerEntry::DIRECTION_OTHER, $txid);
     $loaded_models = array_values(iterator_to_array($repo->findByAccount($account)));
     PHPUnit::assertCount(3, $loaded_models);
     PHPUnit::assertEquals(CurrencyUtil::valueToSatoshis(100), $loaded_models[0]['amount']);
     PHPUnit::assertEquals(CurrencyUtil::valueToSatoshis(200), $loaded_models[1]['amount']);
     PHPUnit::assertEquals(CurrencyUtil::valueToSatoshis(-300), $loaded_models[2]['amount']);
 }
Beispiel #18
0
 public function testBlockUpdatesConfirmationsForListTransactions()
 {
     // run a scenario first
     $this->app->make('\\ScenarioRunner')->init($this)->runScenarioByNumber(6);
     // get the API tester (must be after running the scenario)
     $api_tester = $this->getAPITester();
     // make the current block an arbitrary high number (99)
     $this->app->make('SampleBlockHelper')->createSampleBlock('default_parsed_block_01.json', ['hash' => 'BLOCKHASH99', 'height' => 333099, 'parsed_block' => ['height' => 333099]]);
     // find the address
     $monitored_address = $this->monitoredAddressByAddress('RECIPIENT01');
     $response = $api_tester->callAPIWithAuthentication('GET', '/api/v1/transactions/' . $monitored_address['uuid']);
     PHPUnit::assertEquals(200, $response->getStatusCode(), "Response was: " . $response->getContent());
     $loaded_transactions_from_api = json_decode($response->getContent(), 1);
     // check the confirmations count (100)
     PHPUnit::assertCount(1, $loaded_transactions_from_api);
     PHPUnit::assertEquals(100, $loaded_transactions_from_api[0]['confirmations']);
 }
Beispiel #19
0
 public function testAddAndFindTXOs()
 {
     // add one
     $txo_repository = $this->app->make('App\\Repositories\\TXORepository');
     $txid = $this->TXOHelper()->nextTXID();
     $txid_2 = $this->TXOHelper()->nextTXID();
     $payment_address = app('PaymentAddressHelper')->createSamplePaymentAddressWithoutInitialBalances();
     $sample_txo = $this->TXOHelper()->createSampleTXO($payment_address, ['txid' => $txid, 'n' => 0, 'green' => true]);
     $sample_txo_2 = $this->TXOHelper()->createSampleTXO($payment_address, ['txid' => $txid, 'n' => 1, 'type' => TXO::UNCONFIRMED]);
     $sample_txo_3 = $this->TXOHelper()->createSampleTXO($payment_address, ['txid' => $txid_2, 'n' => 0, 'spent' => 1]);
     // load the txo by id
     $reloaded_txo = $txo_repository->findByID($sample_txo['id']);
     PHPUnit::assertEquals($sample_txo->toArray(), $reloaded_txo->toArray());
     // get all txos by txid
     $reloaded_txos = $txo_repository->findByTXID($txid);
     PHPUnit::assertCount(2, $reloaded_txos);
     // get txos by txid
     PHPUnit::assertEquals($sample_txo->toArray(), $txo_repository->findByTXIDAndOffset($txid, 0)->toArray());
     PHPUnit::assertEquals($sample_txo_2->toArray(), $txo_repository->findByTXIDAndOffset($txid, 1)->toArray());
     PHPUnit::assertEquals($sample_txo_3->toArray(), $txo_repository->findByTXIDAndOffset($txid_2, 0)->toArray());
     // get all txos by payment_address
     $reloaded_txos = $txo_repository->findByPaymentAddress($payment_address);
     PHPUnit::assertCount(3, $reloaded_txos);
     // get all txos by payment_address (filtered by type)
     $reloaded_txos = $txo_repository->findByPaymentAddress($payment_address, [TXO::UNCONFIRMED]);
     PHPUnit::assertCount(1, $reloaded_txos);
     PHPUnit::assertEquals($sample_txo_2->toArray(), $reloaded_txos[0]->toArray());
     // get all txos by payment_address (filtered by unspent)
     $reloaded_txos = $txo_repository->findByPaymentAddress($payment_address, null, true);
     PHPUnit::assertCount(2, $reloaded_txos);
     PHPUnit::assertEquals($sample_txo->toArray(), $reloaded_txos[0]->toArray());
     PHPUnit::assertEquals($sample_txo_2->toArray(), $reloaded_txos[1]->toArray());
     // get all txos by payment_address (filtered by green)
     $reloaded_txos = $txo_repository->findByPaymentAddress($payment_address, null, null, true);
     PHPUnit::assertCount(1, $reloaded_txos);
     PHPUnit::assertEquals($sample_txo->toArray(), $reloaded_txos[0]->toArray());
     // get all txos by payment_address (filtered by all)
     $reloaded_txos = $txo_repository->findByPaymentAddress($payment_address, [TXO::CONFIRMED], true, true);
     PHPUnit::assertCount(1, $reloaded_txos);
     PHPUnit::assertEquals($sample_txo->toArray(), $reloaded_txos[0]->toArray());
 }
 public function testCaseInsensitiveArraySet()
 {
     $assertions = function ($array, $count = 1) {
         PHPUnit_Framework_Assert::assertCount($count, $array);
         PHPUnit_Framework_Assert::assertTrue($array['foo'] === 'bar');
         PHPUnit_Framework_Assert::assertTrue($array['Foo'] === 'bar');
         PHPUnit_Framework_Assert::assertTrue($array['FOo'] === 'bar');
         PHPUnit_Framework_Assert::assertTrue($array['FOO'] === 'bar');
     };
     $array = new CaseInsensitiveArray();
     $array['foo'] = 'bar';
     $assertions($array);
     $array['Foo'] = 'bar';
     $assertions($array);
     $array['FOo'] = 'bar';
     $assertions($array);
     $array['FOO'] = 'bar';
     $assertions($array);
     $array['baz'] = 'qux';
     $assertions($array, 2);
 }
Beispiel #21
0
 public function testDuplicateBlockErrorSendsNotificationsOnce()
 {
     // init mocks
     $mock_calls = app('CounterpartySenderMockBuilder')->installMockCounterpartySenderDependencies($this->app, $this);
     $queue_manager = app('Illuminate\\Queue\\QueueManager');
     $queue_manager->addConnector('sync', function () {
         return new \TestMemorySyncConnector();
     });
     // drain the queue to start
     $queue_manager->connection('notifications_out')->drain();
     // get a single sample user
     $sample_user = app('UserHelper')->createSampleUser(['webhook_endpoint' => null]);
     // add a monitor address for 12iVwKP7jCPnuYy7jbAbyXnZ3FxvgLwvGK
     $created_address = app('MonitoredAddressHelper')->createSampleMonitoredAddress($sample_user, ['address' => '1KUsjZKrkd7LYRV7pbnNJtofsq1HAiz6MF']);
     // build and process a block event with the same transaction ID
     $block_event = $this->buildBlockEvent(['tx' => ["000000000000000000000000000000000000000000000000000000000000001a", "8de3c8666c40f73ae13df0206e9caf83c075c51eb54349331aeeba130b7520c8"]]);
     $network_handler_factory = app('App\\Handlers\\XChain\\Network\\Factory\\NetworkHandlerFactory');
     $block_handler = $network_handler_factory->buildBlockHandler($block_event['network']);
     $block_handler->processBlock($block_event);
     // check mock calls
     $btcd_calls = $mock_calls['btcd'];
     PHPUnit::assertEquals('000000000000000000000000000000000000000000000000000000000000001a', $btcd_calls[0]['args'][0]);
     PHPUnit::assertEquals('8de3c8666c40f73ae13df0206e9caf83c075c51eb54349331aeeba130b7520c8', $btcd_calls[2]['args'][0]);
     // check notifications out
     $notifications = $this->getActualNotifications($queue_manager);
     PHPUnit::assertCount(1, $notifications);
     $payload = json_decode($notifications[0]['payload'], true);
     PHPUnit::assertEquals(['1JztLWos5K7LsqW5E78EASgiVBaCe6f7cD'], $payload['sources']);
     PHPUnit::assertEquals(['1KUsjZKrkd7LYRV7pbnNJtofsq1HAiz6MF'], $payload['destinations']);
     // process the block a second time
     $mock_calls = app('CounterpartySenderMockBuilder')->installMockCounterpartySenderDependencies($this->app, $this);
     // build and process a block event with the same transaction ID
     $block_event = $this->buildBlockEvent(['tx' => ["000000000000000000000000000000000000000000000000000000000000001a", "8de3c8666c40f73ae13df0206e9caf83c075c51eb54349331aeeba130b7520c8"]]);
     $network_handler_factory = app('App\\Handlers\\XChain\\Network\\Factory\\NetworkHandlerFactory');
     $block_handler = $network_handler_factory->buildBlockHandler($block_event['network']);
     $block_handler->processBlock($block_event);
     // check that notifications out is 0 this time
     $notifications = $this->getActualNotifications($queue_manager);
     PHPUnit::assertCount(0, $notifications);
 }
Beispiel #22
0
 public function testFindAllAsOfHeight()
 {
     // insert
     $created_block_model_1 = $this->blockHelper()->createSampleBlock('default_parsed_block_01.json', ['hash' => 'BLOCKHASH01', 'height' => 333000, 'parsed_block' => ['height' => 333000]]);
     $created_block_model_2 = $this->blockHelper()->createSampleBlock('default_parsed_block_01.json', ['hash' => 'BLOCKHASH02', 'height' => 333001, 'parsed_block' => ['height' => 333001]]);
     // create 3 and 4 in the wrong order
     $created_block_model_4 = $this->blockHelper()->createSampleBlock('default_parsed_block_01.json', ['hash' => 'BLOCKHASH04', 'height' => 333003, 'parsed_block' => ['height' => 333003]]);
     $created_block_model_3 = $this->blockHelper()->createSampleBlock('default_parsed_block_01.json', ['hash' => 'BLOCKHASH03', 'height' => 333002, 'parsed_block' => ['height' => 333002]]);
     // load all as of 333003
     $block_repo = $this->app->make('App\\Repositories\\BlockRepository');
     $loaded_block_models = $block_repo->findAllAsOfHeight(333003);
     PHPUnit::assertNotEmpty($loaded_block_models);
     PHPUnit::assertCount(1, $loaded_block_models->all());
     PHPUnit::assertEquals('BLOCKHASH04', $loaded_block_models[0]['hash']);
     // load all as of 333002
     $block_repo = $this->app->make('App\\Repositories\\BlockRepository');
     $loaded_block_models = $block_repo->findAllAsOfHeight(333002);
     PHPUnit::assertNotEmpty($loaded_block_models);
     PHPUnit::assertCount(2, $loaded_block_models->all());
     PHPUnit::assertEquals('BLOCKHASH03', $loaded_block_models[0]['hash']);
     PHPUnit::assertEquals('BLOCKHASH04', $loaded_block_models[1]['hash']);
 }
 public function testCount()
 {
     $this->resolver->setDefault('default', 0);
     $this->resolver->setRequired('required');
     $this->resolver->setDefined('defined');
     $this->resolver->setDefault('lazy1', function () {
     });
     $this->resolver->setDefault('lazy2', function (Options $options) {
         \PHPUnit_Framework_Assert::assertCount(4, $options);
     });
     $this->assertCount(4, $this->resolver->resolve(array('required' => 'value')));
 }
 /**
  * @Then a certificate exists for the domain :domain
  */
 public function aCertificateExistsForTheDomain($domain)
 {
     \PHPUnit_Framework_Assert::assertCount(1, glob($this->storageDir . '/domains/' . $domain . '/cert.pem'));
 }
Beispiel #25
0
 /**
  * @param string|int $count
  *
  * @Given I should see a pager with ":count" pages
  */
 public function assertPager($count)
 {
     \PHPUnit_Framework_Assert::assertCount($count + ($offset = 2), $pages = $this->findPager()->findAll('xpath', '/li'), sprintf('The number of pages "%d" does not match "%d".', count($pages) - $offset, $count));
 }
Beispiel #26
0
 public function toHaveCount($count)
 {
     if ($this->negate) {
         a::assertNotCount($count, $this->actual);
     } else {
         a::assertCount($count, $this->actual);
     }
 }
 public function assertRaised()
 {
     $expected = array();
     foreach ($this->assertions as $assertion) {
         $expected[] = $assertion->getViolation();
     }
     $expected[] = $this->getViolation();
     $violations = iterator_to_array($this->context->getViolations());
     \PHPUnit_Framework_Assert::assertCount(count($expected), $violations);
     reset($violations);
     foreach ($expected as $violation) {
         \PHPUnit_Framework_Assert::assertEquals($violation, current($violations));
         next($violations);
     }
 }
Beispiel #28
0
/**
 * Asserts the number of elements of an array, Countable or Iterator.
 *
 * @param integer $expectedCount
 * @param mixed   $haystack
 * @param string  $message
 */
function assertCount($expectedCount, $haystack, $message = '')
{
    return PHPUnit_Framework_Assert::assertCount($expectedCount, $haystack, $message);
}
 /**
  * @Then /^I should have the following nodes:$/
  */
 public function iShouldHaveTheFollowingNodes(TableNode $table)
 {
     $rows = $table->getHash();
     Assert::assertCount(count($rows), $this->currentNodes, 'Current nodes should match count of examples');
     foreach ($rows as $index => $row) {
         if (isset($row['Path'])) {
             Assert::assertEquals($row['Path'], $this->currentNodes[$index]->getPath(), 'Path should match');
         }
         if (isset($row['Properties'])) {
             Assert::assertEquals(json_decode($row['Properties'], TRUE), $this->currentNodes[$index]->getProperties(), 'Properties should match');
         }
         if (isset($row['Locales'])) {
             $dimensions = $this->currentNodes[$index]->getDimensions();
             Assert::assertEquals($row['Locales'], implode(',', $dimensions['locales']), 'Locale should match');
         }
     }
 }
Beispiel #30
0
 public function count($array)
 {
     a::assertCount($array, $this->actual, $this->description);
 }