public function testCategoriesMethodSetsConditionsWhenUsingMultipleCategories() { $filter = $this->app->make('Giftertipster\\Entity\\ProductSearchFilter\\CategoriesFilter'); $filter->categories(['foo', 'bar']); $expected_conditions = [['group', '=', 'foo'], ['group', '=', 'bar']]; assertThat($filter->conditions(), equalTo($expected_conditions)); }
/** * @test */ public function it_can_retry_a_message() { $id = 1234; $body = 'test'; $routingKey = 'foo'; $priority = 3; $headers = ['foo' => 'bar']; /** @var MockInterface|EnvelopeInterface $envelope */ $envelope = Mock::mock(EnvelopeInterface::class); $envelope->shouldReceive('getDeliveryTag')->andReturn($id); $envelope->shouldReceive('getBody')->andReturn($body); $envelope->shouldReceive('getRoutingKey')->andReturn($routingKey); $envelope->shouldReceive('getPriority')->andReturn($priority); $envelope->shouldReceive('getHeaders')->andReturn($headers); $envelope->shouldReceive('getContentType')->andReturn(MessageProperties::CONTENT_TYPE_BASIC); $envelope->shouldReceive('getDeliveryMode')->andReturn(MessageProperties::DELIVERY_MODE_PERSISTENT); $attempt = 2; $cooldownTime = 60; $cooldownDate = \DateTime::createFromFormat('U', time() + $attempt * $cooldownTime); $publisher = $this->createPublisherMock(); $publisher->shouldReceive('publish')->once()->with(Mock::on(function (Message $retryMessage) use($envelope, $attempt) { $this->assertSame($envelope->getDeliveryTag(), $retryMessage->getId(), 'Delivery tag of the retry-message is not the same'); $this->assertSame($envelope->getBody(), $retryMessage->getBody(), 'Body of the retry-message is not the same'); $this->assertSame($envelope->getRoutingKey(), $retryMessage->getRoutingKey(), 'Routing key of the retry-message is not the same'); $this->assertArraySubset($envelope->getHeaders(), $retryMessage->getHeaders(), 'Headers are not properly cloned'); $this->assertSame($attempt, $retryMessage->getHeader(RetryProcessor::PROPERTY_KEY), 'There should be an "attempt" header in the retry message'); return true; }), equalTo($cooldownDate))->andReturn(true); $strategy = new BackoffStrategy($publisher, $cooldownTime); $result = $strategy->retry($envelope, $attempt); $this->assertTrue($result); }
public function testCreateCsv() { $testDb = new TestLiteDb(); $testDb->createPlainTables(array('license_ref', 'license_map')); $dbManager = $testDb->getDbManager(); $licenses = array(); for ($i = 1; $i < 4; $i++) { $licenses[$i] = array('rf_pk' => $i, 'rf_shortname' => 'lic' . $i, 'rf_fullname' => 'lice' . $i, 'rf_text' => 'text' . $i, 'rf_url' => $i . $i, 'rf_notes' => 'note' . $i, 'rf_source' => 's' . $i, 'rf_detector_type' => 1, 'rf_risk' => $i - 1); $dbManager->insertTableRow('license_ref', $licenses[$i]); } $dbManager->insertTableRow('license_map', array('rf_fk' => 3, 'rf_parent' => 1, 'usage' => LicenseMap::CONCLUSION)); $dbManager->insertTableRow('license_map', array('rf_fk' => 3, 'rf_parent' => 2, 'usage' => LicenseMap::REPORT)); $licenseCsvExport = new LicenseCsvExport($dbManager); $head = array('shortname', 'fullname', 'text', 'parent_shortname', 'report_shortname', 'url', 'notes', 'source', 'risk'); $out = fopen('php://output', 'w'); $csv = $licenseCsvExport->createCsv(); ob_start(); fputcsv($out, $head); fputcsv($out, array($licenses[1]['rf_shortname'], $licenses[1]['rf_fullname'], $licenses[1]['rf_text'], null, null, $licenses[1]['rf_url'], $licenses[1]['rf_notes'], $licenses[1]['rf_source'], $licenses[1]['rf_risk'])); fputcsv($out, array($licenses[2]['rf_shortname'], $licenses[2]['rf_fullname'], $licenses[2]['rf_text'], null, null, $licenses[2]['rf_url'], $licenses[2]['rf_notes'], $licenses[2]['rf_source'], $licenses[2]['rf_risk'])); fputcsv($out, array($licenses[3]['rf_shortname'], $licenses[3]['rf_fullname'], $licenses[3]['rf_text'], $licenses[1]['rf_shortname'], $licenses[2]['rf_shortname'], $licenses[3]['rf_url'], $licenses[3]['rf_notes'], $licenses[3]['rf_source'], $licenses[3]['rf_risk'])); $expected = ob_get_contents(); ob_end_clean(); assertThat($csv, is(equalTo($expected))); $delimiter = '|'; $licenseCsvExport->setDelimiter($delimiter); $csv3 = $licenseCsvExport->createCsv(3); ob_start(); fputcsv($out, $head, $delimiter); fputcsv($out, array($licenses[3]['rf_shortname'], $licenses[3]['rf_fullname'], $licenses[3]['rf_text'], $licenses[1]['rf_shortname'], $licenses[2]['rf_shortname'], $licenses[3]['rf_url'], $licenses[3]['rf_notes'], $licenses[3]['rf_source'], $licenses[3]['rf_risk']), $delimiter); $expected3 = ob_get_contents(); ob_end_clean(); assertThat($csv3, is(equalTo($expected3))); }
public function testShowFolderTreeWithContent() { $res = $this->prepareShowFolderTree($parentFolderId = 'foo'); $this->dbManager->shouldReceive('fetchArray')->with($res)->andReturn($rowTop = array('folder_pk' => 1, 'folder_name' => 'Top', 'folder_desc' => '', 'depth' => 0), $rowA = array('folder_pk' => 2, 'folder_name' => 'B', 'folder_desc' => '/A', 'depth' => 1), $rowB = array('folder_pk' => 3, 'folder_name' => 'B', 'folder_desc' => '/A/B', 'depth' => 2), $rowC = array('folder_pk' => 4, 'folder_name' => 'C', 'folder_desc' => '/C', 'depth' => 1), false); $out = $this->folderNav->showFolderTree($parentFolderId); assertThat(str_replace("\n", '', $out), equalTo('<ul id="tree"><li>' . $this->getFormattedItem($rowTop) . '<ul><li>' . $this->getFormattedItem($rowA) . '<ul><li>' . $this->getFormattedItem($rowB) . '</li></ul></li><li>' . $this->getFormattedItem($rowC) . '</li></ul></li></ul>')); }
public function testCreateRouterFromController() { $controller = new Fixtures\ProductController(); $router = $controller->getRouter(); assertThat($router->getStaticRoutes(), is(equalTo(['' => ['GET' => ['Rootr\\Fixtures\\ProductController', 'indexAction']]]))); assertThat($router->getVariableRoutes(), is(equalTo(['/(\\d+)' => ['GET' => [['Rootr\\Fixtures\\ProductController', 'showAction'], ['id']]], '/delete/([^/]+)' => ['DELETE' => [['Rootr\\Fixtures\\ProductController', 'deleteAction'], ['id']]]]))); }
/** * @test */ public function replace_PhraseWithTwoWordsAndAllWordsExistingInDictionary_ReturnsTranslation() { $dictionary = [$word = 'snow' => 'white watering', $wordB = 'sun' => 'hot lighting']; $this->replacer->setDictionary($dictionary); $result = $this->replacer->replace("It's \${$word}\$ outside and \${$wordB}\$"); assertThat($result, is(equalTo("It's white watering outside and hot lighting"))); }
public function testDiffByKeyWithNonDefaultKey() { $collectionStub = ModelStub::all(); $diff = $this->collection->diffByKey($collectionStub, 'name'); $diffNames = $diff->lists('name'); assertThat($diffNames, is(equalTo(['Taylor Otwell']))); }
public function testRenderContentTextConvertsToUtf8() { $this->pagedTextResult->appendContentText("äöü"); $expected = htmlspecialchars("äöü", ENT_SUBSTITUTE, 'UTF-8'); assertThat($this->pagedTextResult->getText(), is(equalTo($expected))); $this->addToAssertionCount(1); }
public function testExplodeAssocWithCustomGlueArgumentsReturnsCorrectArrayValue() { $string = 'some_key:dummyvalue;another_key:anothervalue'; $expectedArray = ['some_key' => 'dummyvalue', 'another_key' => 'anothervalue']; $explodedValue = explode_assoc($string, ':', ';'); assertThat($explodedValue, is(equalTo($expectedArray))); }
public function testMakeReturnsExpectedQueryWithPollTypeBoostAndFieldSimularitiesAndFieldValueBoost() { $this->query_params = ['gender' => 'male', 'occasion' => 'birthday']; $this->expected_query = ['has_child' => ['type' => 'add', 'score_type' => 'sum', 'query' => ['function_score' => ['query' => ['bool' => ['should' => [['term' => ['gender' => ['value' => 'male', 'boost' => 1]]], ['term' => ['occasion' => ['value' => 'anniversary', 'boost' => 2.0]]], ['term' => ['occasion' => ['value' => 'birthday', 'boost' => 4]]]]]], 'functions' => [['filter' => ['term' => ['add_type' => 'detail_view']], 'boost_factor' => 1.2]]]]]]; $result = $this->gen->make($this->query_params, $this->search_type_config); assertThat($result, equalTo($this->expected_query)); }
public function testTakesMissedContextDescriptionFromGivenArray() { $storage = m::mock(); $storage->shouldReceive('ensurePresence')->with(equalTo(String::create('order/details:title', 'Here are the order details', 'H1 title in GUI', 'vfs://templates/order/details.html')))->once(); $storage->shouldReceive('ensurePresence'); self::crawler($storage, null, self::contextDescriptions())->collectTranslations(array(vfsStream::url('templates')), '.html'); }
public function testMaxPriceMethodSetsCondition($value = '') { $filter = $this->app->make('Giftertipster\\Entity\\ProductSearchFilter\\PriceRangeFilter'); $filter->maxPrice(15); $expected_conditions = [['min_price_amount', '>', 0], ['max_price_amount', '<', 15]]; assertThat($filter->conditions(), equalTo($expected_conditions)); }
public function testIsProductSuiteBlacklistedReturnsFalseWhenItIsNot() { $create_response = $this->eloquent_bp->create(['vendor' => 'vendor.com', 'vendor_id' => 1]); $prod_suite_stub = ['vendor' => 'vendor.com', 'vendor_id' => 2]; assertThat($create_response, equalTo(true)); assertThat($this->eloquent_bp->isProductSuiteBlacklisted($prod_suite_stub), identicalTo(false)); }
public function testGetProfileStringwhenNullIsProvided() { $expected_keyword_string = ''; $service = $this->app->make('Giftertipster\\Service\\KeywordProfile\\KeywordProfileGenerator'); $result = $service->getProfileString(null); assertThat($result, equalTo($expected_keyword_string)); }
public function testIteratesOverAllStringsRegisteringThem() { $storage = m::mock(); $storage->shouldReceive('setTranslationValue')->with(equalTo(String::create('yes', 'Yes')))->once(); $storage->shouldReceive('setTranslationValue')->with(equalTo(String::create('validator:notEmpty', 'Should be not empty', 'Validation error messages')))->once(); $process = new Process($storage); $process->run(array('yes' => array('Yes'), 'validator:notEmpty' => array('Should be not empty', 'Validation error messages'))); }
public function testDispatchNotFoundRoute() { $dispatcher = new Dispatcher($this->router); $response = $dispatcher->dispatch('GET', '/not-found'); assertThat($response, is(anInstanceOf('Rootr\\Response'))); assertThat($this->readAttribute($response, 'status'), is(equalTo(404))); assertThat($this->readAttribute($response, 'body'), is(equalTo('Not Found'))); }
/** @test */ public function itCanBeSerialized() { $requests = $this->prophesize(RequestDefinitions::class); $requests->getIterator()->willReturn(new \ArrayIterator()); $schema = new Schema($requests->reveal()); $serialized = serialize($schema); assertThat(unserialize($serialized), equalTo($schema)); }
/** @test */ public function itShouldDecodeAJsonStringIntoAnArrayOfObject() { $expected = [(object) ['foo' => 'foo1'], (object) ['foo' => 'foo2']]; $data = '[{"foo": "foo1"}, {"foo": "foo2"}]'; $decoder = new SymfonyDecoderAdapter(new JsonDecode(true)); $actual = $decoder->decode($data, 'json'); assertThat($actual, equalTo($expected)); }
/** @test */ public function itCanResolveARequestParameterByName() { $requestParameter = $this->prophesize(Parameter::class); $requestParameter->getLocation()->willReturn('query'); $requestParameter->getName()->willReturn('foo'); $requestParameters = new Parameters([$requestParameter->reveal()]); assertThat($requestParameters->getByName('foo'), equalTo($requestParameter->reveal())); }
public function testCreateUserAnalytic() { Factory::create('Giftertipster\\Entity\\Eloquent\\User', ['permissions' => []]); $response = $this->repo->createUserAnalytic(1, 10); $saved_analytic = UserAnalytic::find(1)->toArray(); assertThat($response, equalTo(true)); assertThat($saved_analytic, hasKeyValuePair('quantity', 10)); assertThat($saved_analytic, hasKeyValuePair('user_id', 1)); }
public function testAnonymousMockWorksWithNotAllowingMockingOfNonExistantMethods() { $before = \Mockery::getConfiguration()->mockingNonExistentMethodsAllowed(); \Mockery::getConfiguration()->allowMockingNonExistentMethods(false); $m = $this->container->mock(); $m->shouldReceive("test123")->andReturn(true); assertThat($m->test123(), equalTo(true)); \Mockery::getConfiguration()->allowMockingNonExistentMethods(true); }
public function testGetCommonHead() { assertThat(StringOperation::getCommonHead('abc', 'abc'), equalTo('abc')); assertThat(StringOperation::getCommonHead('abcd', 'abc'), equalTo('abc')); assertThat(StringOperation::getCommonHead('abc', 'abcd'), equalTo('abc')); assertThat(StringOperation::getCommonHead('abcd', 'abce'), equalTo('abc')); assertThat(StringOperation::getCommonHead('abcdf', 'abcef'), equalTo('abc')); assertThat(StringOperation::getCommonHead('abc', ''), equalTo('')); assertThat(StringOperation::getCommonHead('', 'abc'), equalTo('')); }
public function testRouteWithOptionalVariable() { $pattern = $this->instance->build('/news/{year:\\d{4}}/{month:\\d{2}}/{?slug}'); assertThat($pattern, is(arrayWithSize(2))); list($regEx, $variables) = $pattern; assertThat($regEx, is(equalTo('/news/(\\d{4})/(\\d{2})(?:/([^/]+))?'))); assertThat($variables, is(equalTo(['year', 'month', 'slug']))); assertThat(preg_match('~^' . $regEx . '$~', '/news/2014/05/lastest-news'), is(true)); assertThat(preg_match('~^' . $regEx . '$~', '/news/2014/05'), is(true)); }
public function testSubProductMatchingVendorIdWorks() { $sub_product = Factory::create('Giftertipster\\Entity\\Eloquent\\SubProduct', ['vendor_id' => 'asin stub']); $sub_product2 = Factory::create('Giftertipster\\Entity\\Eloquent\\SubProduct', ['vendor_id' => 'asin stub2']); $sub_product_repo = $this->app->make('Giftertipster\\Repository\\SubProduct\\EloquentSubProductRepository'); $result_sub_product = $sub_product_repo->subProductMatchingVendorId('asin stub'); assertThat($result_sub_product, notNullValue()); assertThat($result_sub_product['id'], equalTo(1)); assertThat($result_sub_product, hasKey('images')); }
public function testUpdateJob() { Artisan::call('migrate'); RangeCronJob::create(['job_name' => 'foobar job', 'last_id_processed' => 1, 'last_status' => 'fooness']); $job = $this->repo->findJob('foobar job'); assertThat($job, anInstanceOf('Giftertipster\\Entity\\Eloquent\\RangeCronJob')); $this->repo->updateJob($job, 'test status', 0); $updated_job = $this->repo->findJob('foobar job'); assertThat($updated_job->last_status, identicalTo('test status')); assertThat($updated_job->last_id_processed, equalTo(0)); }
/** @test */ public function itCanCreateAResponseDefinition() { $schemaFile = 'file://' . __DIR__ . '/../fixtures/petstore.json'; $factory = new SwaggerSchemaFactory(); $schema = $factory->createSchema($schemaFile); $responseDefinition = $schema->getRequestDefinition('addPet')->getResponseDefinition(200); assertThat($responseDefinition, isInstanceOf(ResponseDefinition::class)); assertThat($responseDefinition->getContentTypes(), contains('application/json')); assertThat($responseDefinition->getBodySchema(), isType('object')); assertThat($responseDefinition->getStatusCode(), equalTo(200)); }
public function testOperation() { $CartGetOperation = $this->app->make('Giftertipster\\Service\\Api\\AmzProductApi\\ApaiIO\\Operations\\CartGetOperation'); $CartGetOperation->setCartId('cart id stub'); $CartGetOperation->setHMAC('hmac stub'); $params = $CartGetOperation->getOperationParameter(); assertThat($CartGetOperation->getName(), equalTo('CartGet')); assertThat($params, arrayWithSize(2)); assertThat($params, hasKeyValuePair('CartId', 'cart id stub')); assertThat($params, hasKeyValuePair('HMAC', 'hmac stub')); }
public function testResolve() { $items = array('item1' => array('deps' => null, 'id' => 'item1'), 'item2' => array('deps' => null, 'id' => 'item2'), 'item3' => array('deps' => array('item2'), 'id' => 'item3'), 'item4' => array('deps' => array('item1', 'item3'), 'id' => 'item4'), 'item5' => array('deps' => array('item4', 'item6'), 'id' => 'item5'), 'item6' => array('deps' => array('item2'), 'id' => 'item6'), 'item7' => array('deps' => array('something-odd'), 'id' => 'item7'), 'item9' => array('deps' => array('item6', 'item5', 'item4'), 'id' => 'item9'), 'item10' => array('deps' => array('item9'), 'id' => 'item10'), 'item11' => array('deps' => array('item1', 'item2', 'item10'), 'id' => 'item11')); $expected = array('item1', 'item2', 'item3', 'item4', 'item6', 'item5', 'item9', 'item10', 'item11'); $resolver = new DependencyResolver(); $resolved = $resolver->register($items)->resolveAll(); foreach ($expected as $index => $id) { assertThat($resolved, hasKeyInArray($index)); assertThat($resolved[$index]['id'], is(equalTo($id))); } }
public function testCreateFailsIfIdeaAlreadyExistsAndReturnsFalseWithErrors() { Factory::create('Giftertipster\\Entity\\Eloquent\\User', ['permissions' => []]); $idea_repo = $this->app->make('Giftertipster\\Repository\\Idea\\EloquentIdeaRepository'); $new_idea = 'blender'; $response = $idea_repo->create(['user_id' => 1, 'description' => $new_idea, 'is_fulfilled' => 0]); $idea = $this->eloquent_idea->find(1); $response = $idea_repo->create(['user_id' => 1, 'description' => $new_idea, 'is_fulfilled' => 0]); $errors = $idea_repo->errors(); assertThat($response, identicalTo(false)); assertThat($errors->first(), equalTo('The description has already been taken.')); }
public function testReturnCorrectAttributeData() { $stub = Mockery::mock('PullAutomaticallyGalleries\\RemoteApi\\RemoteApiModelInterface')->shouldReceive('connect')->with('')->andReturn($this->userStub)->getMock(); Test::double('RemoteUser', ['newModel' => $stub]); $user = RemoteUser::connect('DummyHost', ''); assertThat($user->id, containsString('dummyhost_1')); assertThat($user->realname, is(equalTo($this->userStub['realname']))); assertThat($user->username, is(equalTo($this->userStub['username']))); assertThat($user->url, is(equalTo($this->userStub['url']))); assertThat($user->credentials, is(equalTo($this->userStub['credentials']))); assertThat($user->host, is(equalTo('DummyHost'))); }