Skip to content

Commit 80f2dae

Browse files
committed
new tests implemented
1 parent 35c75ac commit 80f2dae

File tree

5 files changed

+96
-1
lines changed

5 files changed

+96
-1
lines changed

phpunit.xml.dist

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
convertNoticesToExceptions="true"
99
convertWarningsToExceptions="true"
1010
processIsolation="false"
11-
stopOnFailure="false">
11+
stopOnFailure="true">
1212
<testsuites>
1313
<testsuite name="AwesIO Repository Package">
1414
<directory suffix=".php">./tests/</directory>

tests/Stubs/Scope.php

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
3+
namespace AwesIO\Repository\Tests\Stubs;
4+
5+
use AwesIO\Repository\Scopes\ScopeAbstract;
6+
7+
class Scope extends ScopeAbstract
8+
{
9+
public function mappings()
10+
{
11+
return ['full_name' => 'name'];
12+
}
13+
14+
public function scope($builder, $value, $scope)
15+
{
16+
$scope = $this->resolveScopeValue($scope);
17+
18+
return $builder->where($scope, $value);
19+
}
20+
}

tests/Unit/Scopes/OrderByTest.php

+24
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,30 @@
88

99
class OrderByTest extends TestCase
1010
{
11+
/** @test */
12+
public function it_has_mappings()
13+
{
14+
$scope = new OrderByScope;
15+
16+
$this->assertEquals([], $scope->mappings());
17+
}
18+
19+
/** @test */
20+
public function it_returns_ignores_wrong_order_postfix()
21+
{
22+
factory(Model::class, 5)->create();
23+
24+
$scope = new OrderByScope;
25+
26+
$results = Model::get();
27+
28+
$this->assertEquals(1, $results->first()->id);
29+
30+
$results = $scope->scope(new Model, 'id_wrong-order-postfix', '')->get();
31+
32+
$this->assertEquals(1, $results->first()->id);
33+
}
34+
1135
/** @test */
1236
public function it_orders_by_asc()
1337
{

tests/Unit/Scopes/ScopeTest.php

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
3+
namespace AwesIO\Repository\Tests\Unit\Scopes;
4+
5+
use AwesIO\Repository\Tests\TestCase;
6+
use Illuminate\Support\Facades\Request;
7+
use AwesIO\Repository\Tests\Stubs\Model;
8+
use AwesIO\Repository\Tests\Stubs\Scope;
9+
10+
class ScopeTest extends TestCase
11+
{
12+
/** @test */
13+
public function it_resolves_scope_value()
14+
{
15+
factory(Model::class, 5)->create();
16+
17+
$model = factory(Model::class)->create();
18+
19+
$scope = new Scope;
20+
21+
$results = $scope->scope(new Model, $model->name, 'full_name')->get();
22+
23+
$this->assertEquals($model->id, $results->first()->id);
24+
}
25+
}

tests/Unit/Scopes/ScopesTest.php

+26
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,32 @@
99

1010
class ScopesTest extends TestCase
1111
{
12+
/** @test */
13+
public function it_scopes_request_by_field()
14+
{
15+
$request = Request::create(
16+
'/',
17+
'GET',
18+
['name' => 'name']
19+
);
20+
21+
$scopes = new Scopes($request, ['name' => 'like']);
22+
23+
factory(Model::class, 5)->create();
24+
25+
$model = factory(Model::class)->create([
26+
'name' => 'name'
27+
]);
28+
29+
$results = Model::get();
30+
31+
$this->assertEquals(1, $results->first()->id);
32+
33+
$results = $scopes->scope(new Model)->get();
34+
35+
$this->assertEquals($model->id, $results->first()->id);
36+
}
37+
1238
/** @test */
1339
public function it_scopes_request_by_orderBy()
1440
{

0 commit comments

Comments
 (0)