Skip to content

Commit

Permalink
Merge pull request #24 from LaraChimp/feature/laravel-8
Browse files Browse the repository at this point in the history
Laravel 8 support
  • Loading branch information
percymamedy authored Sep 15, 2021
2 parents 3803797 + 7c709de commit 70b454c
Show file tree
Hide file tree
Showing 24 changed files with 199 additions and 135 deletions.
3 changes: 0 additions & 3 deletions .styleci.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1 @@
preset: laravel

disabled:
- simplified_null_return
10 changes: 5 additions & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ env:
matrix:
fast_finish: true
include:
- php: 7.2
- php: 7.2
env: SETUP=lowest
- php: 7.3
- php: 7.3
env: SETUP=lowest
- php: 7.4snapshot
- php: 7.4snapshot
- php: 7.4
- php: 7.4
env: SETUP=lowest
- php: 8.0
- php: 8.0
env: SETUP=lowest

cache:
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ Mango Repo is open-sourced software licensed under the [MIT license](http://open
5.8.x | 0.4.x
6.x | 1.x
7.x | 2.x
8.x | 3.x

### Installation
Install Mango Repo as you would with any other dependency managed by Composer:
Expand Down
12 changes: 6 additions & 6 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@
}
],
"require": {
"php": "^7.2",
"illuminate/support": "^7.0",
"larachimp/pine-annotations": "^2.0"
"php": "^7.3|^8.0",
"illuminate/support": "^8.0",
"larachimp/pine-annotations": "^3.0"
},
"require-dev": {
"mockery/mockery": "^1.3.1",
"orchestra/testbench": "^5.0",
"phpunit/phpunit": "^8.4|^9.0"
"mockery/mockery": "^1.4.3",
"orchestra/testbench": "^6.0",
"phpunit/phpunit": "^9.3.3"
},
"autoload": {
"psr-4": {
Expand Down
1 change: 1 addition & 0 deletions src/Annotations/EloquentModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class EloquentModel
* use for the repository.
*
* @Required
*
* @var string
*/
public $target;
Expand Down
21 changes: 8 additions & 13 deletions src/Concerns/IsRepositorable.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ trait IsRepositorable
/**
* Sets the Model to the Repo.
*
* @param Model $model
*
* @param Model $model
* @return self
*/
public function setModel(Model $model)
Expand All @@ -40,10 +39,9 @@ public function getModel()
/**
* Update a Model in the database.
*
* @param array $values
* @param \Illuminate\Database\Eloquent\Model|mixed $idOrModel
* @param array $options
*
* @param array $values
* @param \Illuminate\Database\Eloquent\Model|mixed $idOrModel
* @param array $options
* @return bool
*/
public function update(array $values, $idOrModel, array $options = [])
Expand All @@ -58,8 +56,7 @@ public function update(array $values, $idOrModel, array $options = [])
/**
* Delete a record from the database.
*
* @param \Illuminate\Database\Eloquent\Model|mixed $idOrModel
*
* @param \Illuminate\Database\Eloquent\Model|mixed $idOrModel
* @return bool|null
*
* @throws \Exception
Expand All @@ -76,9 +73,8 @@ public function delete($idOrModel)
/**
* Find a Model or Models Using some criteria.
*
* @param array $criteria
* @param array $columns
*
* @param array $criteria
* @param array $columns
* @return \Illuminate\Database\Eloquent\Collection|null
*/
public function findBy($criteria = [], $columns = ['*'])
Expand All @@ -101,8 +97,7 @@ public function findBy($criteria = [], $columns = ['*'])
/**
* Return response from repository.
*
* @param mixed $value
*
* @param mixed $value
* @return mixed
*/
protected function response($value)
Expand Down
3 changes: 1 addition & 2 deletions src/Concerns/IsRepositoryBootable.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,7 @@ protected function getEloquentModelByAnnotation()
/**
* Find the first Eloquent Model specified by the annotations.
*
* @param Collection $annotations
*
* @param Collection $annotations
* @return Model
*/
protected function findFirstEloquentModel(Collection $annotations)
Expand Down
5 changes: 2 additions & 3 deletions src/Concerns/IsRepositoryScopable.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,8 @@ trait IsRepositoryScopable
* Whenever a function is called we try to
* scope it to the model.
*
* @param string $name
* @param mixed $arguments
*
* @param string $name
* @param mixed $arguments
* @return $this
*/
public function __call($name, $arguments)
Expand Down
5 changes: 2 additions & 3 deletions src/Console/MakeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,8 @@ protected function getStub()
/**
* Replace the namespace for the given stub.
*
* @param string $stub
* @param string $name
*
* @param string $stub
* @param string $name
* @return $this
*/
protected function replaceNamespace(&$stub, $name)
Expand Down
15 changes: 6 additions & 9 deletions src/Contracts/RepositoryInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,29 +7,26 @@ interface RepositoryInterface
/**
* Update a Model in the database.
*
* @param array $values
* @param \Illuminate\Database\Eloquent\Model|mixed $idOrModel
* @param array $options
*
* @param array $values
* @param \Illuminate\Database\Eloquent\Model|mixed $idOrModel
* @param array $options
* @return bool
*/
public function update(array $values, $idOrModel, array $options = []);

/**
* Delete a record from the database.
*
* @param \Illuminate\Database\Eloquent\Model|mixed $idOrModel
*
* @param \Illuminate\Database\Eloquent\Model|mixed $idOrModel
* @return mixed
*/
public function delete($idOrModel);

/**
* Find a Model or Models Using some criteria.
*
* @param array $criteria
* @param array $columns
*
* @param array $criteria
* @param array $columns
* @return \Illuminate\Database\Eloquent\Collection|null
*/
public function findBy($criteria = [], $columns = ['*']);
Expand Down
6 changes: 3 additions & 3 deletions src/Exceptions/InvalidModelException.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ class InvalidModelException extends \RuntimeException
/**
* InvalidModelException constructor.
*
* @param string $message
* @param int $code
* @param Exception|null $previous
* @param string $message
* @param int $code
* @param Exception|null $previous
*/
public function __construct($message = '', $code = 0, Exception $previous = null)
{
Expand Down
6 changes: 3 additions & 3 deletions src/Exceptions/UnspecifiedModelException.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ class UnspecifiedModelException extends \RuntimeException
/**
* UnspecifiedModelException constructor.
*
* @param string $message
* @param int $code
* @param Exception|null $previous
* @param string $message
* @param int $code
* @param Exception|null $previous
*/
public function __construct($message = '', $code = 0, Exception $previous = null)
{
Expand Down
21 changes: 2 additions & 19 deletions tests/AbstractTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ protected function setUp(): void
{
parent::setUp();
$this->createAppropriateTables();
$this->withFactories(__DIR__.'/Fixtures/database/factories');
}

/**
Expand All @@ -36,8 +35,7 @@ protected function tearDown(): void
/**
* Get package providers.
*
* @param \Illuminate\Foundation\Application $app
*
* @param \Illuminate\Foundation\Application $app
* @return array
*/
protected function getPackageProviders($app)
Expand All @@ -48,25 +46,10 @@ protected function getPackageProviders($app)
];
}

/**
* Get package aliases.
*
* @param \Illuminate\Foundation\Application $app
*
* @return array
*/
protected function getPackageAliases($app)
{
return [
'Acme' => 'Acme\Facade',
];
}

/**
* Define environment setup.
*
* @param \Illuminate\Foundation\Application $app
*
* @param \Illuminate\Foundation\Application $app
* @return void
*/
protected function getEnvironmentSetUp($app)
Expand Down
29 changes: 29 additions & 0 deletions tests/Fixtures/Database/Factories/BarFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

namespace LaraChimp\MangoRepo\Tests\Fixtures\Database\Factories;

use Illuminate\Database\Eloquent\Factories\Factory;
use LaraChimp\MangoRepo\Tests\Fixtures\Models\Bar;

class BarFactory extends Factory
{
/**
* The name of the factory's corresponding model.
*
* @var string
*/
protected $model = Bar::class;

/**
* Define the model's default state.
*
* @return array
*/
public function definition()
{
return [
'name' => $this->faker->name,
'is_active' => true,
];
}
}
28 changes: 28 additions & 0 deletions tests/Fixtures/Database/Factories/FooFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

namespace LaraChimp\MangoRepo\Tests\Fixtures\Database\Factories;

use Illuminate\Database\Eloquent\Factories\Factory;
use LaraChimp\MangoRepo\Tests\Fixtures\Models\Foo;

class FooFactory extends Factory
{
/**
* The name of the factory's corresponding model.
*
* @var string
*/
protected $model = Foo::class;

/**
* Define the model's default state.
*
* @return array
*/
public function definition()
{
return [
'name' => $this->faker->name,
];
}
}
33 changes: 33 additions & 0 deletions tests/Fixtures/Database/Factories/UserFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

namespace LaraChimp\MangoRepo\Tests\Fixtures\Database\Factories;

use Illuminate\Database\Eloquent\Factories\Factory;
use Illuminate\Support\Str;
use LaraChimp\MangoRepo\Tests\Fixtures\Models\User;

class UserFactory extends Factory
{
/**
* The name of the factory's corresponding model.
*
* @var string
*/
protected $model = User::class;

/**
* Define the model's default state.
*
* @return array
*/
public function definition()
{
return [
'name' => $this->faker->name,
'email' => $this->faker->unique()->safeEmail,
'password' => bcrypt('secret'),
'remember_token' => Str::random(10),
'is_active' => true,
];
}
}
15 changes: 15 additions & 0 deletions tests/Fixtures/Models/Bar.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,16 @@

namespace LaraChimp\MangoRepo\Tests\Fixtures\Models;

use Illuminate\Database\Eloquent\Factories\Factory;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use LaraChimp\MangoRepo\Tests\Fixtures\Database\Factories\BarFactory;
use LaraChimp\MangoRepo\Tests\Fixtures\Models\Scopes\IsActive;

class Bar extends Model
{
use HasFactory;

/**
* The attributes that are mass assignable.
*
Expand All @@ -28,4 +33,14 @@ protected static function boot()

static::addGlobalScope(new IsActive());
}

/**
* Create a new factory instance for the model.
*
* @return Factory
*/
protected static function newFactory()
{
return BarFactory::new();
}
}
Loading

0 comments on commit 70b454c

Please sign in to comment.