Skip to content

Commit

Permalink
Follow Laravel 6 (#21)
Browse files Browse the repository at this point in the history
* Chore: Bump dependency version

* Refactor: Remove useless invoker

Laravel has `getPivotAccessor()` since v5.5

* Fix: Follow latest PHPUnit changes

* Test: Cast pivot_id as integer

Laravel doesn't automatically cast `pivot_id` anymore since version 5.8

* Chore: Ignore .phpunit.result.cache
  • Loading branch information
mpyw authored Sep 20, 2019
1 parent 41beb61 commit 17e7465
Show file tree
Hide file tree
Showing 12 changed files with 40 additions and 29 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ composer.lock
/vendor/
/build/logs/
.php_cs.cache
.phpunit.result.cache
2 changes: 1 addition & 1 deletion .scrutinizer.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ filter:
build:

environment:
php: '7.1'
php: '7.3'

dependencies:
before:
Expand Down
14 changes: 8 additions & 6 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ language: php

matrix:
exclude:
- php: 5.6
env: LARAVEL_VERSION=5.5.* TESTBENCH_VERSION=3.5.*
- env: LARAVEL_VERSION=^6.0 TESTBENCH_VERSION=^4.0
php: 7.1

php:
- 5.6
- 7.0
- 7.3
- 7.2
- 7.1

cache:
Expand All @@ -16,8 +16,10 @@ cache:
- $HOME/.composer/cache

env:
- LARAVEL_VERSION=5.4.* TESTBENCH_VERSION=3.4.* PHPUNIT_VERSION=5.7.*
- LARAVEL_VERSION=5.5.* TESTBENCH_VERSION=3.5.*
- LARAVEL_VERSION=^6.0 TESTBENCH_VERSION=^4.0
- LARAVEL_VERSION=5.8.* TESTBENCH_VERSION=3.8.*
- LARAVEL_VERSION=5.7.* TESTBENCH_VERSION=3.7.*
- LARAVEL_VERSION=5.6.* TESTBENCH_VERSION=3.6.*

before_script:
- composer self-update
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ Rapid pagination without using OFFSET

## Requirements

- PHP: ^5.6 || ^7.0
- Laravel: ^5.4
- PHP: ^7.1
- Laravel: ^5.6 || ^6.0
- [lampager/lampager](https://github.com/lampager/lampager): ^0.4

## Installing
Expand Down
7 changes: 4 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,13 @@
}
},
"require": {
"php": "^5.6 || ^7.0",
"php": "^7.1",
"ext-json": "*",
"lampager/lampager": "^0.4"
},
"require-dev": {
"orchestra/testbench": "^3.5",
"laravel/framework": "^5.4",
"orchestra/testbench": "^4.0",
"laravel/framework": "^6.0",
"php-coveralls/php-coveralls": "^1.0",
"nilportugues/sql-query-formatter": "^1.2"
},
Expand Down
11 changes: 1 addition & 10 deletions src/Processor.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,16 +77,7 @@ protected function pivotField($row, $column, $accessor)
*/
protected function pivotAccessor()
{
if (method_exists($this->builder, 'getPivotAccessor')) {
return $this->builder->getPivotAccessor();
}
static $invoker;
if (!$invoker) {
$invoker = function () {
return isset($this->accessor) ? $this->accessor : 'pivot';
};
}
return $invoker->bindTo($this->builder, $this->builder)->__invoke();
return $this->builder->getPivotAccessor();
}

/**
Expand Down
4 changes: 2 additions & 2 deletions tests/FormatterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,19 +54,19 @@ public function testInstanceCustomFormatter()

/**
* @test
* @expectedException \InvalidArgumentException
*/
public function testInvalidFormatter()
{
$this->expectException(\InvalidArgumentException::class);
Post::lampager()->useProcessor(function () {});
}

/**
* @test
* @expectedException \InvalidArgumentException
*/
public function testInvalidProcessor()
{
$this->expectException(\InvalidArgumentException::class);
Post::lampager()->useFormatter(__CLASS__);
}
}
2 changes: 1 addition & 1 deletion tests/MySQLGrammarTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ protected function getEnvironmentSetUp($app)
// Skip SQLite setup and use default MySQL configuration
}

protected function setUp()
protected function setUp(): void
{
// Skip SQLite setup and use default MySQL configuration
BaseTestCase::setUp();
Expand Down
15 changes: 15 additions & 0 deletions tests/PostTagPivot.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

namespace Lampager\Laravel\Tests;

use Illuminate\Database\Eloquent\Relations\Pivot;

/**
* Class PostTagPivot
*/
class PostTagPivot extends Pivot
{
protected $casts = [
'id' => 'int',
];
}
5 changes: 3 additions & 2 deletions tests/ProcessorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -462,11 +462,12 @@ public function testBelongsToMany()

/**
* @test
* @expectedException \Exception
* @expectedExceptionMessage The column `id` is not included in the pivot "pivot".
*/
public function testBelongsToManyWithoutPivotKey()
{
$this->expectException(\Exception::class);
$this->expectExceptionMessage('The column `id` is not included in the pivot "pivot".');

Tag::find(1)->posts()
->lampager()
->forward()->limit(3)
Expand Down
2 changes: 1 addition & 1 deletion tests/Tag.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,6 @@ class Tag extends Model

public function posts()
{
return $this->belongsToMany(Post::class);
return $this->belongsToMany(Post::class)->using(PostTagPivot::class);
}
}
2 changes: 1 addition & 1 deletion tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ protected function getPackageProviders($app)
];
}

protected function setUp()
protected function setUp(): void
{
parent::setUp();

Expand Down

0 comments on commit 17e7465

Please sign in to comment.