-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
return null when barcode find returns product without code + phpunit …
…tests
- Loading branch information
Showing
5 changed files
with
88 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
C:37:"PHPUnit\Runner\DefaultTestResultCache":120:{a:2:{s:7:"defects";a:0:{}s:5:"times";a:1:{s:60:"Palmans\LaravelOpenFoodFacts\Tests\ExampleTest::true_is_true";d:0.005;}}} | ||
C:37:"PHPUnit\Runner\DefaultTestResultCache":1449:{a:2:{s:7:"defects";a:5:{s:92:"Palmans\LaravelOpenFoodFacts\Tests\BarcodeFindTest::it_returns_a_document_when_product_found";i:4;s:90:"Palmans\LaravelOpenFoodFacts\Tests\BarcodeFindTest::it_returns_null_when_product_not_found";i:3;s:94:"Palmans\LaravelOpenFoodFacts\Tests\BarcodeFindTest::it_throws_an_exception_when_argument_empty";i:3;s:99:"Palmans\LaravelOpenFoodFacts\Tests\ProductSearchTest::it_returns_a_laravelcollection_with_documents";i:3;s:113:"Palmans\LaravelOpenFoodFacts\Tests\ProductSearchTest::it_returns_an_empty_laravelcollection_when_no_results_found";i:3;}s:5:"times";a:8:{s:60:"Palmans\LaravelOpenFoodFacts\Tests\ExampleTest::true_is_true";d:0.005;s:92:"Palmans\LaravelOpenFoodFacts\Tests\BarcodeFindTest::it_returns_a_document_when_product_found";d:0.508;s:90:"Palmans\LaravelOpenFoodFacts\Tests\BarcodeFindTest::it_returns_null_when_product_not_found";d:0.215;s:84:"Palmans\LaravelOpenFoodFacts\Tests\ProductSearchTest::it_returns_a_laravelcollection";d:0.227;s:94:"Palmans\LaravelOpenFoodFacts\Tests\BarcodeFindTest::it_throws_an_exception_when_argument_empty";d:0.026;s:99:"Palmans\LaravelOpenFoodFacts\Tests\ProductSearchTest::it_returns_a_laravelcollection_with_documents";d:0.24;s:113:"Palmans\LaravelOpenFoodFacts\Tests\ProductSearchTest::it_returns_an_empty_laravelcollection_when_no_results_found";d:0.189;s:96:"Palmans\LaravelOpenFoodFacts\Tests\ProductSearchTest::it_throws_an_exception_on_too_many_results";d:0.811;}}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
<?php | ||
|
||
namespace Palmans\LaravelOpenFoodFacts\Tests; | ||
|
||
use Orchestra\Testbench\TestCase; | ||
use Palmans\LaravelOpenFoodFacts\Facades\OpenFoodFacts; | ||
|
||
class BarcodeFindTest extends TestCase | ||
{ | ||
protected function getPackageProviders($app) | ||
{ | ||
return [\Palmans\LaravelOpenFoodFacts\OpenFoodFactsServiceProvider::class]; | ||
} | ||
|
||
/** @test */ | ||
public function it_returns_a_document_when_product_found() | ||
{ | ||
$doc = OpenFoodFacts::barcode('0737628064502'); | ||
|
||
$this->assertInstanceOf(\OpenFoodFacts\Document::class, $doc); | ||
} | ||
|
||
/** @test */ | ||
public function it_returns_null_when_product_not_found() | ||
{ | ||
$doc = OpenFoodFacts::barcode('this-barcode-does-not-exist'); | ||
|
||
$this->assertNull($doc); | ||
} | ||
|
||
/** @test */ | ||
public function it_throws_an_exception_when_argument_empty() | ||
{ | ||
$this->expectException("InvalidArgumentException"); | ||
$this->expectExceptionMessage("Argument must represent a barcode"); | ||
|
||
OpenFoodFacts::barcode(''); | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
<?php | ||
|
||
namespace Palmans\LaravelOpenFoodFacts\Tests; | ||
|
||
use OpenFoodFacts\Document; | ||
use Orchestra\Testbench\TestCase; | ||
use Palmans\LaravelOpenFoodFacts\Facades\OpenFoodFacts; | ||
|
||
class ProductSearchTest extends TestCase | ||
{ | ||
protected function getPackageProviders($app) | ||
{ | ||
return [\Palmans\LaravelOpenFoodFacts\OpenFoodFactsServiceProvider::class]; | ||
} | ||
|
||
/** @test */ | ||
public function it_returns_a_laravelcollection_with_documents() | ||
{ | ||
$results = OpenFoodFacts::find('Stir-Fry Rice Noodles'); | ||
|
||
$this->assertInstanceOf(\Illuminate\Support\Collection::class, $results); | ||
|
||
$this->assertTrue($results->isNotEmpty()); | ||
|
||
$results->each(function($doc) { | ||
$this->assertInstanceOf(\OpenFoodFacts\Document::class, $doc); | ||
}); | ||
} | ||
|
||
/** @test */ | ||
public function it_returns_an_empty_laravelcollection_when_no_results_found() | ||
{ | ||
$results = OpenFoodFacts::find('no-such-product-exists'); | ||
|
||
$this->assertTrue($results->isEmpty()); | ||
} | ||
|
||
/** @test */ | ||
public function it_throws_an_exception_on_too_many_results() | ||
{ | ||
$this->expectException("Exception"); | ||
|
||
OpenFoodFacts::find('cola'); | ||
} | ||
} |