Skip to content

Commit 09bf4f5

Browse files
committed
Inicio do desenvolvimento dos testes utilizando os repositories do sistema
1 parent f20da8a commit 09bf4f5

File tree

3 files changed

+91
-3
lines changed

3 files changed

+91
-3
lines changed

tests/Application.php

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
use Illuminate\Container\Container;
1010
use Illuminate\Database\Eloquent\Model;
1111
use Illuminate\Database\Schema\Blueprint;
12+
use Illuminate\Events\Dispatcher;
13+
use Illuminate\Http\Request;
1214
use PHPUnit\Framework\TestCase;
1315

1416
class Application extends TestCase
@@ -19,6 +21,20 @@ protected function setUp()
1921
{
2022
parent::setUp();
2123

24+
$this->startContainer();
25+
}
26+
27+
public static function setUpBeforeClass()
28+
{
29+
parent::setUpBeforeClass();
30+
31+
$static = new static();
32+
$static->startContainer();
33+
$static->dropData();
34+
}
35+
36+
protected function startContainer()
37+
{
2238
$this->app = new Container();
2339

2440
$this->app->singleton('config', function()
@@ -38,12 +54,19 @@ protected function setUp()
3854
return new FirebirdDatabaseManager($app, $app['db.factory']);
3955
});
4056

57+
$this->app->singleton('events', function($app)
58+
{
59+
return new Dispatcher($app);
60+
});
61+
62+
$this->app->singleton('request', function() {
63+
return new Request();
64+
});
65+
4166
Container::setInstance($this->app);
4267

4368
Model::setConnectionResolver($this->app['db']);
44-
45-
// $this->recriateTables();
46-
$this->dropData();
69+
Model::setEventDispatcher($this->app['events']);
4770
}
4871

4972
public function dropData()

tests/Repositories/Users.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?php
2+
3+
namespace Tests\Repositories;
4+
5+
use Masterkey\Repository\AbstractRepository;
6+
use Tests\Models\User;
7+
8+
class Users extends AbstractRepository
9+
{
10+
public function model()
11+
{
12+
return User::class;
13+
}
14+
}

tests/UsersRepositoryTest.php

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
<?php
2+
3+
namespace Tests;
4+
5+
use Faker\Factory;
6+
use Illuminate\Pagination\Paginator;
7+
use Tests\Models\User;
8+
use Tests\Repositories\Users;
9+
10+
class UsersRepositoryTest extends Application
11+
{
12+
public function testCreateUser()
13+
{
14+
$faker = Factory::create('pt_BR');
15+
16+
$users = new Users($this->app);
17+
18+
$users->create(['NAME' => $faker->name, 'EMAIL' => $faker->safeEmail]);
19+
20+
$this->assertEquals(1, $users->count());
21+
}
22+
23+
public function testFirst()
24+
{
25+
$users = new Users($this->app);
26+
27+
$this->assertInstanceOf(User::class, $users->first());
28+
}
29+
30+
public function testSimplePagination()
31+
{
32+
$faker = Factory::create('pt_BR');
33+
$users = new Users($this->app);
34+
35+
for ($i = 0; $i < 10; $i++) {
36+
$users->create(['NAME' => $faker->name, 'EMAIL' => $faker->safeEmail]);
37+
}
38+
39+
$pagination = $users->simplePaginate(5);
40+
41+
$this->assertInstanceOf(Paginator::class, $pagination);
42+
}
43+
44+
public function testFullPagination()
45+
{
46+
$users = new Users($this->app);
47+
$pagination = $users->paginate(5);
48+
49+
var_dump($pagination);
50+
}
51+
}

0 commit comments

Comments
 (0)