Пример #1
0
 /**
  * @test
  */
 public function remove_withObject_removesObjectFromDirectory()
 {
     $object = Mockery::mock('FileSystem\\Tests\\Assets\\Object')->shouldIgnoreMissing();
     $object->name = 'object';
     $this->directory->add($object);
     $this->directory->remove($object);
     assertThat($this->directory->objects, noneOf(hasKey($object->name), hasItem($object)));
 }
Пример #2
0
 public function testInsertData()
 {
     $testDb = new TestLiteDb();
     $testDb->createPlainTables(array('perm_upload'));
     $testDb->insertData(array('perm_upload'));
     $tag1 = $testDb->getDbManager()->getSingleRow('select perm from perm_upload where perm_upload_pk=1');
     assertThat($tag1, hasKey('perm'));
     assertThat($tag1['perm'], is(10));
 }
 /**
  * @test
  */
 public function cacheFileContainsSerializedAnnotationData()
 {
     $annotations = new Annotations('someTarget');
     AnnotationCache::put($annotations);
     AnnotationCache::__shutdown();
     $data = unserialize(file_get_contents(vfsStream::url('root/annotations.cache')));
     assert($data, hasKey('someTarget'));
     assert(unserialize($data['someTarget']), equals($annotations));
 }
 public function testFilterGalleryAttributesFromMetaFieldsWhenSaves()
 {
     $attributes = ['post_content' => 'Dummy Content.', 'post_title' => 'Dummy Title', 'post_date' => date('Y-m-d H:i:s'), 'pal_user_id' => 1, 'pal_gallery_id' => 1];
     $gallery = new Gallery($attributes);
     $gallery->save();
     $attributes = $gallery->getAttributes();
     assertThat($attributes, hasKey('post_content'));
     assertThat($attributes, hasKey('post_title'));
     assertThat($attributes, hasKey('post_date'));
     assertThat($attributes, not(hasKey('pal_user_id')));
     assertThat($attributes, not(hasKey('pal_gallery_id')));
 }
 public function testSubProductForCartAddWorks()
 {
     $sub_product = Factory::create('Giftertipster\\Entity\\Eloquent\\SubProduct', ['id' => 1, 'vendor_id' => 'asin stub', 'offer_listing_id' => 'offer listing id stub']);
     $image = Factory::make('Giftertipster\\Entity\\Eloquent\\Image', ['category' => 'variation']);
     $image2 = Factory::make('Giftertipster\\Entity\\Eloquent\\Image', ['category' => 'primary']);
     $sub_product->images()->save($image);
     $sub_product->images()->save($image2);
     $sub_product2 = Factory::create('Giftertipster\\Entity\\Eloquent\\SubProduct');
     $sub_product_repo = $this->app->make('Giftertipster\\Repository\\SubProduct\\EloquentSubProductRepository');
     $result_sub_product = $sub_product_repo->subProductDataForCartAdd(1);
     assertThat($result_sub_product, hasKeyValuePair('id', 1));
     assertThat($result_sub_product, hasKey('images'));
     assertThat($result_sub_product['images'], not(emptyArray()));
 }
Пример #6
0
 function testCreateMap()
 {
     $keyColumn = 'yek';
     $valueColumn = 'lav';
     $tableName = 'foo';
     $sqlLog = 'bar';
     $preSql = "/ {$keyColumn}, *{$valueColumn} /";
     $this->driver->shouldReceive('query')->andReturn('fakeRes');
     $this->driver->shouldReceive('fetchArray')->andReturn(array($keyColumn => 'k0', $valueColumn => 'v0'), array($keyColumn => 'k1', $valueColumn => 'v1'), false);
     $this->driver->shouldReceive('freeResult');
     $map = $this->dbManager->createMap($tableName, $keyColumn, $valueColumn, $sqlLog);
     assertThat($map, hasKey('k0'));
     assertThat($map, EqualTo(array('k0' => 'v0', 'k1' => 'v1')));
 }
Пример #7
0
 public function testAddGroupMembership()
 {
     $this->testDb->createPlainTables(array('users', 'groups', 'group_user_member'));
     $this->testDb->insertData(array('users', 'groups', 'group_user_member'));
     $this->userDao->addGroupMembership($groupId = 2, $userId = 1);
     $map = $this->userDao->getUserGroupMap($userId);
     assertThat($map, hasKey($groupId));
 }
 public function testFind()
 {
     $seed_product = Factory::create('Giftertipster\\Entity\\Eloquent\\Product', ['group' => 'bar1']);
     $seed_product2 = Factory::create('Giftertipster\\Entity\\Eloquent\\Product', ['group' => 'bar2']);
     $seed_image1 = Factory::create('Giftertipster\\Entity\\Eloquent\\Image', ['imageable_id' => 2, 'imageable_type' => 'Giftertipster\\Entity\\Eloquent\\Product']);
     $seed_image2 = Factory::create('Giftertipster\\Entity\\Eloquent\\Image', ['imageable_id' => 2, 'imageable_type' => 'Giftertipster\\Entity\\Eloquent\\Product']);
     $seed_feature1 = Factory::create('Giftertipster\\Entity\\Eloquent\\Feature', ['description' => 'first product feature', 'featurable_id' => 2, 'featurable_type' => 'Giftertipster\\Entity\\Eloquent\\Product']);
     $seed_feature2 = Factory::create('Giftertipster\\Entity\\Eloquent\\Feature', ['description' => 'second product feature', 'featurable_id' => 2, 'featurable_type' => 'Giftertipster\\Entity\\Eloquent\\Product']);
     $seed_variation1 = Factory::create('Giftertipster\\Entity\\Eloquent\\Variation', ['sub_product_id' => 2]);
     $product = $this->app->make('Giftertipster\\Repository\\Product\\EloquentProductRepository');
     $products = $product->find(2);
     assertThat($products, hasKeyValuePair('id', 2));
     assertThat($products, not(hasKey('images')));
     assertThat($products, not(hasKey('features')));
     assertThat($products, not(hasKey('variations')));
 }
 public function testGetCategorySelections()
 {
     $this->createStubCategories();
     //make another interest and sub interest for this test
     $interest = Factory::create('Giftertipster\\Entity\\Eloquent\\Category\\InterestCategory', ['priority' => 5]);
     $sub_interest = Factory::create('Giftertipster\\Entity\\Eloquent\\Category\\SubInterestCategory', ['priority' => 5, 'interest_category_id' => 2]);
     $this->repo = $this->app->make('Giftertipster\\Repository\\Categories\\EloquentCategoriesRepository');
     $result = $this->repo->getCategorySelections($this->repo->getCategories(true));
     assertThat($result, hasKey('Occasion'));
     assertThat($result['Occasion'], hasKey('occasion.1'));
     assertThat($result['Occasion'], hasKey('occasion.2'));
     assertThat($result['Occasion'], hasKey('occasion.3'));
     assertThat($result, hasKey('Relation'));
     assertThat($result['Relation'], hasKey('relation.1'));
     assertThat($result, hasKey('Age'));
     assertThat($result['Age'], hasKey('age.1'));
     assertThat($result, hasKey('Gender'));
     assertThat($result['Gender'], hasKey('gender.1'));
     assertThat($result, hasKey('Interest'));
     assertThat($result['Interest'], hasKey('interest.1'));
     assertThat($result['Interest'], hasKey('interest.2'));
     assertThat($result, hasKey('Sub Interest'));
     assertThat($result['Sub Interest'], hasKey('sub_interest.1'));
     assertThat($result['Sub Interest'], hasKey('sub_interest.2'));
 }
Пример #10
0
function fHasKey($p)
{
    return function ($d) use($p) {
        return hasKey($p, $d);
    };
}
Пример #11
0
/**
 * @param string   $key
 * @param callable $callback
 * @return \Closure
 */
function keyApply($key, callable $callback)
{
    if (!is_string($key)) {
        return never();
    }
    return combine(hasKey($key), function ($item) use($key, $callback) {
        $args = func_get_args();
        $args[0] = polymorphicKeyValue($item, $key);
        return variadicCallBoolVal($callback, $args);
    });
}
 public function testGetIncompleteProductLoadsWhenIdHasProduct()
 {
     $user = Factory::create('Giftertipster\\Entity\\Eloquent\\User', ['permissions' => ['test']]);
     $prod_req = Factory::create('Giftertipster\\Entity\\Eloquent\\ProductRequest', ['created_at' => Carbon::tomorrow(), 'user_id' => 1, 'product_id' => 1, 'vendor' => 'foo', 'vendor_id' => 'bar']);
     $idea = Factory::create('Giftertipster\\Entity\\Eloquent\\Idea', ['created_at' => Carbon::today(), 'user_id' => 1, 'description' => 'foobar idea', 'is_fulfilled' => 0]);
     $repo_result = $this->repo()->getIncompleteProductLoads(1);
     //since keys aren't adjusted after sorting, re apply keys:
     foreach ($repo_result as $item) {
         $result[] = $item;
     }
     assertThat($result, not(emptyArray()));
     assertThat($result[0], hasKeyValuePair('type', 'idea load'));
     assertThat($result[0], hasKey('created_at'));
     assertThat($result[0], hasKey('updated_at'));
     assertThat($result[0], hasKey('description'));
     assertThat($result[0], hasKeyValuePair('query', ['idea_description' => 'foobar idea']));
     assertThat($result[0], hasKey('human_time_diff'));
     assertThat($result, not(hasKey(1)));
 }
 public function testDoesNotMatchArrayMissingKey()
 {
     $array = array('a' => 1, 'b' => 2, 'c' => 3);
     $this->assertMismatchDescription('array was ["a" => <1>, "b" => <2>, "c" => <3>]', hasKey('d'), $array);
 }
Пример #14
0
 public function testGetJobInfo()
 {
     $this->dbManager->prepare($stmt = 'insert.jobqueue', "INSERT INTO jobqueue (jq_pk, jq_job_fk, jq_type, jq_args, jq_starttime, jq_endtime, jq_endtext, jq_end_bits, jq_schedinfo, jq_itemsprocessed)" . "VALUES (\$1, \$2, \$3, \$4,\$5, \$6,\$7,\$8,\$9,\$10)");
     $nowTime = time();
     $diffTime = 2345;
     $nomosTime = date('Y-m-d H:i:sO', $nowTime - $diffTime);
     $uploadArrayQue = array(array(8, $jobId = 1, "nomos", 1, $nomosTime, null, "Started", 0, "localhost.5963", $itemNomos = 147), array(1, $jobId, "ununpack", 1, "2015-04-21 18:29:19.23825+05:30", "2015-04-21 18:29:26.396562+05:30", "Completed", 1, null, $itemCount = 646));
     foreach ($uploadArrayQue as $uploadEntry) {
         $this->dbManager->freeResult($this->dbManager->execute($stmt, $uploadEntry));
     }
     $this->dbManager->prepare($stmt = 'insert.uploadtree_a', "INSERT INTO uploadtree_a (uploadtree_pk, parent, upload_fk, pfile_fk, ufile_mode, lft, rgt, ufile_name)" . "VALUES (\$1, \$2, \$3, \$4,\$5, \$6, \$7, \$8)");
     $uploadTreeArray = array(array(123, 121, 1, 103, 32768, 542, 543, "fckeditorcode_ie.js"), array(121, 120, 1, 0, 536888320, 537, 544, "js"), array(715, 651, 2, 607, 33188, 534, 535, "zconf.h.cmakein"), array(915, 651, 2, 606, 33188, 532, 533, "zconf.h"));
     foreach ($uploadTreeArray as $uploadEntry) {
         $this->dbManager->freeResult($this->dbManager->execute($stmt, $uploadEntry));
     }
     $this->dbManager->prepare($stmt = 'insert.jobdepends', "INSERT INTO jobdepends (jdep_jq_fk, jdep_jq_depends_fk) VALUES (\$1, \$2 )");
     $jqWithTwoDependencies = 8;
     $jobDependsArray = array(array(2, 1), array(3, 2), array(4, 2), array(5, 2), array(6, 2), array($jqWithTwoDependencies, 4), array($jqWithTwoDependencies, 4));
     foreach ($jobDependsArray as $uploadEntry) {
         $this->dbManager->freeResult($this->dbManager->execute($stmt, $uploadEntry));
     }
     $testMyJobInfo = $this->showJobsDao->getJobInfo($this->job_pks);
     assertThat($testMyJobInfo, hasKey($jobId));
     assertThat($testMyJobInfo[$jobId]['jobqueue'][$jqWithTwoDependencies]['depends'], is(arrayWithSize(2)));
     $testFilesPerSec = 0.23;
     $formattedEstimatedTime = $this->showJobsDao->getEstimatedTime($job_pk = 1, $jq_Type = "nomos", $testFilesPerSec);
     assertThat($formattedEstimatedTime, matchesPattern('/\\d+:\\d{2}:\\d{2}/'));
     $hourMinSec = explode(':', $formattedEstimatedTime);
     assertThat($hourMinSec[0] * 3600 + $hourMinSec[1] * 60 + $hourMinSec[2], is(closeTo(($itemCount - $itemNomos) / $testFilesPerSec, 0.5 + $testFilesPerSec)));
     $testGetEstimatedTime = $this->showJobsDao->getEstimatedTime($job_pk = 1, $jq_Type, 0);
     assertThat($testGetEstimatedTime, matchesPattern('/\\d+:\\d{2}:\\d{2}/'));
     $hourMinSec = explode(':', $testGetEstimatedTime);
     $tolerance = 0.5 + ($itemCount - $itemNomos) / $itemNomos + (time() - $nowTime);
     assertThat($hourMinSec[0] * 3600 + $hourMinSec[1] * 60 + $hourMinSec[2], is(closeTo(($itemCount - $itemNomos) / $itemNomos * $diffTime, $tolerance)));
     $fewFilesPerSec = 0.003;
     $formattedLongTime = $this->showJobsDao->getEstimatedTime($job_pk = 1, $jq_Type = "nomos", $fewFilesPerSec);
     assertThat($formattedLongTime, matchesPattern('/\\d+:\\d{2}:\\d{2}/'));
     $hourMinSec = explode(':', $formattedLongTime);
     assertThat($hourMinSec[0] * 3600 + $hourMinSec[1] * 60 + $hourMinSec[2], is(closeTo(($itemCount - $itemNomos) / $fewFilesPerSec, 0.5 + $fewFilesPerSec)));
 }
Пример #15
0
 public function testGetCommitsOfLastDays()
 {
     $result = $this->repositoryApi->getCommitsOfLastDays(60);
     assertThat($result, is(not(emptyArray())));
     assertThat($result[0], hasKey('sha'));
 }
 public function testAddPopularitySearchReturnsResultOnSuccess()
 {
     //product
     $this->es_client->index(['index' => $this->product_index, 'type' => $this->product_type, 'id' => 100, 'body' => ['title' => 'test product', 'min_price' => 20000, 'max_price' => 20000, 'datetime' => '2014-02-14 00:01:01', 'group' => 'testgroup1', 'soft_delete_status' => 0], 'refresh' => true]);
     //product
     $this->es_client->index(['index' => $this->product_index, 'type' => $this->product_type, 'id' => 200, 'body' => ['title' => 'test product2', 'min_price' => 30000, 'max_price' => 20000, 'datetime' => '2014-02-14 00:01:01', 'group' => 'testgroup2', 'soft_delete_status' => 0], 'refresh' => true]);
     //add
     $this->es_client->index(['index' => $this->add_index, 'type' => $this->add_type, 'id' => 1, 'parent' => 100, 'body' => ['gender_ids' => 1, 'interest_ids' => [1, 2], 'datetime' => '2014-02-14 00:01:01'], 'refresh' => true]);
     //add
     $this->es_client->index(['index' => $this->add_index, 'type' => $this->add_type, 'id' => 2, 'parent' => 100, 'body' => ['gender_ids' => 2, 'interest_ids' => [2], 'datetime' => '2014-02-14 00:01:01'], 'refresh' => true]);
     //add
     $this->es_client->index(['index' => $this->add_index, 'type' => $this->add_type, 'id' => 3, 'parent' => 200, 'body' => ['gender_ids' => 1, 'interests\\_ids' => [2], 'datetime' => '2014-02-14 00:01:01'], 'refresh' => true]);
     \Config::shouldReceive('get')->with('laravel-elasticsearch-repository::index.index_models.product_add.setup.type')->andReturn('add');
     $result = $this->repo->model('product')->search('add_count', null, 0, 100);
     assertThat($result, hasKey('results'));
     assertThat($result['results'], not(emptyArray()));
     assertThat($result['results'][0], not(hasKey('_source')));
     assertThat($result['meta']['total_hits'], atLeast(1));
     assertThat($result, hasKey('facets'));
     assertThat($result['facets'], hasKey('price'));
     assertThat($result['facets']['price'], not(emptyArray()));
     assertThat($result['facets'], hasKey('group'));
 }
 public function testAddPopularitySearchReturnsResultOnSuccess()
 {
     //product
     $this->client->index(['index' => $this->product_index, 'type' => $this->product_type, 'id' => 100, 'body' => ['title' => 'test product', 'min_price' => 20000, 'max_price' => 20000, 'datetime' => '2014-02-14 00:01:01', 'group' => 'testgroup1', 'soft_delete_status' => 0], 'refresh' => true]);
     //product
     $this->client->index(['index' => $this->product_index, 'type' => $this->product_type, 'id' => 200, 'body' => ['title' => 'test product2', 'min_price' => 30000, 'max_price' => 20000, 'datetime' => '2014-02-14 00:01:01', 'group' => 'testgroup2', 'soft_delete_status' => 0], 'refresh' => true]);
     //add
     $this->client->index(['index' => $this->add_index, 'type' => $this->add_type, 'id' => 1, 'parent' => 100, 'body' => ['gender_ids' => 1, 'interest_ids' => [1, 2], 'datetime' => '2014-02-14 00:01:01'], 'refresh' => true]);
     //add
     $this->client->index(['index' => $this->add_index, 'type' => $this->add_type, 'id' => 2, 'parent' => 100, 'body' => ['gender_ids' => 2, 'interest_ids' => [2], 'datetime' => '2014-02-14 00:01:01'], 'refresh' => true]);
     //add
     $this->client->index(['index' => $this->add_index, 'type' => $this->add_type, 'id' => 3, 'parent' => 200, 'body' => ['gender_ids' => 1, 'interests\\_ids' => [2], 'datetime' => '2014-02-14 00:01:01'], 'refresh' => true]);
     $result = $this->repo->AddPopularitySearch(0, 100);
     assertThat($result, hasKey('results'));
     assertThat($result['results'], not(emptyArray()));
     assertThat($result['results'][0], not(hasKey('_source')));
     assertThat($result['meta']['total_hits'], atLeast(1));
     assertThat($result, hasKey('facets'));
     assertThat($result['facets'], hasKey('price'));
     assertThat($result['facets']['price'], not(emptyArray()));
     assertThat($result['facets'], hasKey('group'));
 }
 public function testRandomFeaturedListingProducts()
 {
     $product_1 = Factory::create('Giftertipster\\Entity\\Eloquent\\Product');
     $product_2 = Factory::create('Giftertipster\\Entity\\Eloquent\\Product');
     $product_3 = Factory::create('Giftertipster\\Entity\\Eloquent\\Product');
     $product_4 = Factory::create('Giftertipster\\Entity\\Eloquent\\Product');
     $image_1 = Factory::create('Giftertipster\\Entity\\Eloquent\\Image', ['imageable_type' => 'Giftertipster\\Entity\\Eloquent\\Product', 'imageable_id' => 1, 'category' => 'primary']);
     $image_2 = Factory::create('Giftertipster\\Entity\\Eloquent\\Image', ['imageable_type' => 'Giftertipster\\Entity\\Eloquent\\Product', 'imageable_id' => 2, 'category' => 'primary']);
     $image_3 = Factory::create('Giftertipster\\Entity\\Eloquent\\Image', ['imageable_type' => 'Giftertipster\\Entity\\Eloquent\\Product', 'imageable_id' => 3, 'category' => 'primary']);
     $image_4 = Factory::create('Giftertipster\\Entity\\Eloquent\\Image', ['imageable_type' => 'Giftertipster\\Entity\\Eloquent\\Product', 'imageable_id' => 4, 'category' => 'primary']);
     $image_1b = Factory::create('Giftertipster\\Entity\\Eloquent\\Image', ['imageable_type' => 'Giftertipster\\Entity\\Eloquent\\Product', 'imageable_id' => 1, 'category' => 'varient']);
     $image_2b = Factory::create('Giftertipster\\Entity\\Eloquent\\Image', ['imageable_type' => 'Giftertipster\\Entity\\Eloquent\\Product', 'imageable_id' => 2, 'category' => 'varient']);
     $image_3b = Factory::create('Giftertipster\\Entity\\Eloquent\\Image', ['imageable_type' => 'Giftertipster\\Entity\\Eloquent\\Product', 'imageable_id' => 3, 'category' => 'varient']);
     $image_4b = Factory::create('Giftertipster\\Entity\\Eloquent\\Image', ['imageable_type' => 'Giftertipster\\Entity\\Eloquent\\Product', 'imageable_id' => 4, 'category' => 'varient']);
     $featured_listing_1 = Factory::create('Giftertipster\\Entity\\Eloquent\\FeaturedListing', ['listing' => 'listing 1']);
     $description_1 = Factory::create('Giftertipster\\Entity\\Eloquent\\Description', ['descriptionable_type' => 'Giftertipster\\Entity\\Eloquent\\Product', 'descriptionable_id' => 1]);
     $description_2 = Factory::create('Giftertipster\\Entity\\Eloquent\\Description', ['descriptionable_type' => 'Giftertipster\\Entity\\Eloquent\\Product', 'descriptionable_id' => 2]);
     $description_3 = Factory::create('Giftertipster\\Entity\\Eloquent\\Description', ['descriptionable_type' => 'Giftertipster\\Entity\\Eloquent\\Product', 'descriptionable_id' => 3]);
     $description_4 = Factory::create('Giftertipster\\Entity\\Eloquent\\Description', ['descriptionable_type' => 'Giftertipster\\Entity\\Eloquent\\Product', 'descriptionable_id' => 4]);
     $featured_listing_1->products()->attach($product_1);
     $featured_listing_1->products()->attach($product_3);
     $featured_listing_2 = Factory::create('Giftertipster\\Entity\\Eloquent\\FeaturedListing', ['listing' => 'listing 1']);
     $featured_listing_2->products()->attach($product_2);
     $featured_listing_2->products()->attach($product_4);
     $repo = $this->app->make('Giftertipster\\Repository\\ProductSuite\\EloquentProductSuiteRepository');
     $listing = $repo->randomFeatureListingProducts();
     assertThat($listing, hasKey('listing'));
     assertThat($listing, hasKey('products'));
     assertThat($listing['products'], arrayWithsize(2));
     assertThat($listing['products'][0], hasKey('images'));
     assertThat($listing['products'][0]['images'], not(emptyArray()));
     assertThat($listing['products'][0]['images'][0]['category'], equalTo('primary'));
     assertThat($listing['products'][0], hasKey('descriptions'));
     assertThat($listing['products'][0]['descriptions'], not(emptyArray()));
 }