Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test runners, and #604 fix #607

Merged
merged 3 commits into from
Jan 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There must be one blank line after the namespace declaration



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

protected $with = ['author'];

}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The closing brace for the class must go on the next line after the body

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);
}

}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The closing brace for the class must go on the next line after the body