Skip to content

Commit

Permalink
Merge pull request #607 from cviebrock/issue605
Browse files Browse the repository at this point in the history
test runners, and #604 fix
  • Loading branch information
cviebrock authored Jan 6, 2024
2 parents a774e4b + 6a8f173 commit ba62135
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 9 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:

steps:
- name: Checkout code
uses: actions/checkout@v2
uses: actions/checkout@v3
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
Expand All @@ -27,9 +27,9 @@ jobs:
run: echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json"
- name: Get composer cache directory
id: composer-cache
run: echo "::set-output name=dir::$(composer config cache-files-dir)"
run: echo "dir=$(composer config cache-files-dir)" >> "$GITHUB_OUTPUT"
- name: Cache dependencies
uses: actions/cache@v2
uses: actions/cache@v3
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: dependencies-${{ matrix.php }}-${{ matrix.stability }}-composer-${{ hashFiles('**/composer.lock') }}
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"require-dev": {
"mockery/mockery": "^1.4.4",
"orchestra/testbench": "^8.0",
"pestphp/pest": "2.x-dev"
"pestphp/pest": "^2.28"
},
"autoload": {
"psr-4": {
Expand Down
10 changes: 6 additions & 4 deletions phpunit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,9 @@
processIsolation="false"
stopOnFailure="true"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.0/phpunit.xsd"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.5/phpunit.xsd"
>
<coverage>
<include>
<directory suffix=".php">src/</directory>
</include>
<report>
<html outputDirectory="build/coverage"/>
</report>
Expand All @@ -26,4 +23,9 @@
<logging>
<junit outputFile="build/report.junit.xml"/>
</logging>
<source>
<include>
<directory suffix=".php">src/</directory>
</include>
</source>
</phpunit>
4 changes: 3 additions & 1 deletion src/Services/SlugService.php
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,9 @@ protected function getExistingSlugs(string $slug, string $attribute, array $conf
}

// get the list of all matching slugs
$results = $query->select([$attribute, $this->model->getQualifiedKeyName()])
$results = $query
->withoutEagerLoads()
->select([$attribute, $this->model->getQualifiedKeyName()])
->get()
->toBase();

Expand Down
14 changes: 14 additions & 0 deletions tests/Models/PostWithEagerRelation.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php namespace Cviebrock\EloquentSluggable\Tests\Models;


/**
* Class PostWithEagerRelations
*
* @package Cviebrock\EloquentSluggable\Tests\Models
*/
class PostWithEagerRelation extends PostWithRelation
{

protected $with = ['author'];

}
41 changes: 41 additions & 0 deletions tests/RelationTests.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php namespace Cviebrock\EloquentSluggable\Tests;

use Cviebrock\EloquentSluggable\Tests\Models\Author;
use Cviebrock\EloquentSluggable\Tests\Models\PostWithEagerRelation;
use Illuminate\Database\Eloquent\Model;

/**
* Class RelationTests
*
* @package Tests
*/
class RelationTests extends TestCase
{

/**
* Test basic slugging functionality.
*/
public function testEagerLoading(): void
{
Model::shouldBeStrict(true);

$author = Author::create([
'name' => 'Arthur Conan Doyle'
]);
$post = new PostWithEagerRelation([
'title' => 'My First Post'
]);
$post->author()->associate($author);
$post->save();

self::assertEquals('arthur-conan-doyle-my-first-post', $post->slug);

$post2 = new PostWithEagerRelation([
'title' => 'My second post',
]);
$post2->author()->associate($author);
$post2->save();
self::assertEquals('arthur-conan-doyle-my-second-post', $post2->slug);
}

}

0 comments on commit ba62135

Please sign in to comment.