Skip to content

Commit 84954a5

Browse files
committed
Merge branch 'develop'
2 parents 2e7aeb9 + 402993c commit 84954a5

File tree

9 files changed

+106
-26
lines changed

9 files changed

+106
-26
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,4 @@ install:
1212
- composer install
1313

1414
script:
15-
- "./vendor/bin/phpunit --coverage-text"
15+
- "./vendor/bin/phpunit --testdox --coverage-text"

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
[![Latest Stable Version](https://poser.pugx.org/pp-spaces/laravel-repository/v/stable)](https://packagist.org/packages/pp-spaces/laravel-repository)
44
[![Total Downloads](https://poser.pugx.org/pp-spaces/laravel-repository/downloads)](https://packagist.org/packages/pp-spaces/laravel-repository)
5+
[![Build Status](https://travis-ci.org/pp-spaces/laravel-repository.svg?branch=develop)](https://travis-ci.org/pp-spaces/laravel-repository)
56
[![License](https://poser.pugx.org/pp-spaces/laravel-repository/license)](https://packagist.org/packages/pp-spaces/laravel-repository)
67

78
## Contents

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
},
5151
"scripts": {
5252
"test": [
53-
"vendor/bin/phpunit --testdox --coverage-text"
53+
"vendor/bin/phpunit --testdox"
5454
]
5555
}
5656
}

src/Facade/Repository.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
3+
namespace PPSpaces\Facade;
4+
5+
use Illuminate\Support\Facades\Facade;
6+
7+
/**
8+
* @see \PPSpaces\Repositories\Repository
9+
*/
10+
class Repository extends Facade
11+
{
12+
/**
13+
* Get the registered name of the component.
14+
*
15+
* @return string
16+
*/
17+
protected static function getFacadeAccessor()
18+
{
19+
return 'PPSpaces\Repositories\Repository';
20+
}
21+
}

src/Repositories/Repository.php

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44

55
use ReflectionClass;
66

7-
use Illuminate\Container\Container as App;
8-
97
use Illuminate\Database\Eloquent\Model;
108
use Illuminate\Contracts\Routing\UrlRoutable;
119

@@ -57,9 +55,8 @@ abstract class Repository implements RepositoryContract, UrlRoutable
5755
* @param \Illuminate\Database\Eloquent\Model $model
5856
* @return void
5957
*/
60-
public function __construct(App $app) {
61-
$this->app = $app;
62-
58+
public function __construct() {
59+
// Initialize Repository Instance
6360
$this->initializeRepository();
6461
}
6562

@@ -69,7 +66,9 @@ public function __construct(App $app) {
6966
* @param \Illuminate\Database\Query\Builder $query
7067
* @return void
7168
*/
72-
abstract public function before($query);
69+
public function before($query) {
70+
//
71+
}
7372

7473
/**
7574
* Get all of the models from the database.
@@ -139,7 +138,9 @@ public function delete($id) {
139138
* @param \Illuminate\Support\Collection|array|int $ids
140139
* @return int
141140
*/
142-
abstract static function destroy($ids);
141+
static function destroy($ids) {
142+
//
143+
}
143144

144145
/**
145146
* Specify Model class name
@@ -158,14 +159,20 @@ public function model() {
158159
* @throws PPSpaces\Exceptions\RepositoryException
159160
*/
160161
public function initializeRepository() {
162+
// Loading application instance
163+
$this->app = app();
164+
165+
// Making model
161166
$model = $this->app->make($this->model);
162167

163168
if (!$model instanceof Model) {
164169
throw new RepositoryException("Class {$this->model} must be an instance of Illuminate\\Database\\Eloquent\\Model");
165170
}
166171

172+
// Create repository model query
167173
$this->repository = $model->newQuery();
168174

175+
// Inject before scope
169176
$this->before($this->repository);
170177
}
171178

@@ -215,6 +222,6 @@ public function __toString()
215222
return $this->resolved->toJson();
216223
}
217224

218-
return null;
225+
return $this->get()->toJson();
219226
}
220227
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
3+
namespace PPSpaces\Tests\Feature\App;
4+
5+
use PPSpaces\Tests\App\User;
6+
use PPSpaces\Tests\TestCase;
7+
use PPSpaces\Tests\App\Http\Repositories\UserRepository;
8+
use Illuminate\Container\Container as App;
9+
10+
/**
11+
* Class DatabaseTest
12+
*/
13+
class RepositoryTest extends TestCase
14+
{
15+
public function test_it_get_datas_from_repository()
16+
{
17+
// When we have 50 users
18+
$users = factory(User::class, 50)->create();
19+
20+
// Then make make the repository
21+
$users = new UserRepository();
22+
23+
// Should give us all available users
24+
$this->assertCount(50, $users->get());
25+
}
26+
}

tests/Feature/Console/RepositoryTest.php

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,6 @@ public function test_it_can_generate_repository_command()
1414
{
1515
$this->artisan('make:repository', [
1616
'name' => 'LogsRepository'
17-
])
18-
->expectsOutput('Repository created successfully.')
19-
->assertExitCode(0);
20-
}
21-
22-
public function test_it_can_generate_model_repository_command()
23-
{
24-
$this->artisan('make:repository', [
25-
'name' => 'UserRepository',
26-
'--model' => 'PPSpaces\Tests\App\User'
27-
])
28-
->expectsOutput('Repository created successfully.')
29-
->assertExitCode(0);
17+
])->assertExitCode(0);
3018
}
3119
}

tests/TestCase.php

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,34 @@ abstract class TestCase extends BaseTestCase
99
use CreatesDatabase;
1010

1111
/**
12-
* To load your package service provider
12+
* Get package providers. At a minimum this is the package being tested, but also
13+
* would include packages upon which our package depends, e.g. Cartalyst/Sentry
14+
* In a normal app environment these would be added to the 'providers' array in
15+
* the config/app.php file.
1316
*
14-
* @param [mixed] $app
15-
* @return void
17+
* @param \Illuminate\Foundation\Application $app
18+
*
19+
* @return array
1620
*/
1721
protected function getPackageProviders($app)
1822
{
1923
return ['PPSpaces\RepositoryServiceProvider'];
2024
}
25+
26+
/**
27+
* Get package aliases. In a normal app environment these would be added to
28+
* the 'aliases' array in the config/app.php file. If your package exposes an
29+
* aliased facade, you should add the alias here, along with aliases for
30+
* facades upon which your package depends, e.g. Cartalyst/Sentry.
31+
*
32+
* @param \Illuminate\Foundation\Application $app
33+
*
34+
* @return array
35+
*/
36+
protected function getPackageAliases($app)
37+
{
38+
return [
39+
'PPSpaces' => 'PPSpaces\Facade'
40+
];
41+
}
2142
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
3+
namespace PPSpaces\Tests\App\Http\Repositories;
4+
5+
use PPSpaces\Repositories\Repository;
6+
7+
class UserRepository extends Repository {
8+
9+
/**
10+
* The \PPSpaces\Tests\App\User model instance.
11+
*
12+
* @var \PPSpaces\Tests\App\User
13+
*/
14+
protected $model = "PPSpaces\Tests\App\User";
15+
16+
}

0 commit comments

Comments
 (0)