Skip to content
This repository has been archived by the owner on Oct 20, 2023. It is now read-only.

Commit

Permalink
Start upgrade
Browse files Browse the repository at this point in the history
  • Loading branch information
grantholle committed May 10, 2023
1 parent a46f5ec commit b3b1f03
Show file tree
Hide file tree
Showing 8 changed files with 57 additions and 51 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ tests/__fixtures__/users/*.yaml
tests/__fixtures__/content/collections/*.yaml
tests/__fixtures__/content/collections/**/*.md
composer.lock
.phpunit.cache
8 changes: 4 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@
}
},
"require": {
"php": "^7.4 || ^8.0 || ^8.1",
"statamic/cms": "3.4.*"
"php": "^8.2",
"statamic/cms": "^4.0"
},
"require-dev": {
"nunomaduro/collision": "^4.2 || ^5.0 || ^6.1",
"orchestra/testbench": "^5.0 || ^6.0 || ^7.0"
"nunomaduro/collision": "^7.0",
"orchestra/testbench": "^8.0"
},
"scripts": {
"lint": [
Expand Down
48 changes: 20 additions & 28 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -1,30 +1,22 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit backupGlobals="false"
backupStaticAttributes="false"
bootstrap="vendor/autoload.php"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false"
printerClass="NunoMaduro\Collision\Adapters\Phpunit\Printer">
<testsuites>
<testsuite name="Test Suite">
<directory suffix="Test.php">./tests</directory>
</testsuite>
</testsuites>
<filter>
<whitelist processUncoveredFilesFromWhitelist="true">
<directory suffix=".php">./app</directory>
</whitelist>
</filter>
<php>
<env name="APP_ENV" value="testing"/>
<env name="APP_KEY" value="base64:xRIcDp1ReW8Y8rd9V9D7hOVV4TI7ThCF3FKxRg01Rm8="/>
<env name="CACHE_DRIVER" value="array"/>
<env name="SESSION_DRIVER" value="array"/>
<env name="QUEUE_DRIVER" value="sync"/>
<env name="MAIL_DRIVER" value="array"/>
</php>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" backupGlobals="false" bootstrap="vendor/autoload.php" colors="true" processIsolation="false" stopOnFailure="false" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.1/phpunit.xsd" cacheDirectory=".phpunit.cache" backupStaticProperties="false">
<coverage/>
<testsuites>
<testsuite name="Test Suite">
<directory suffix="Test.php">./tests</directory>
</testsuite>
</testsuites>
<php>
<env name="APP_ENV" value="testing"/>
<env name="APP_KEY" value="base64:xRIcDp1ReW8Y8rd9V9D7hOVV4TI7ThCF3FKxRg01Rm8="/>
<env name="CACHE_DRIVER" value="array"/>
<env name="SESSION_DRIVER" value="array"/>
<env name="QUEUE_DRIVER" value="sync"/>
<env name="MAIL_DRIVER" value="array"/>
</php>
<source>
<include>
<directory suffix=".php">./app</directory>
</include>
</source>
</phpunit>
2 changes: 1 addition & 1 deletion src/Actions/DuplicateEntryAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ protected function generateTitleAndSlug(AnEntry $entry, $attempt = 1)
$slug .= '-' . $attempt;

// If the slug we've just built already exists, we'll try again, recursively.
if (Entry::findBySlug($slug, $entry->collection()->handle())) {
if (Entry::findByUri($slug, $entry->collection()->handle())) {
$generate = $this->generateTitleAndSlug($entry, $attempt + 1);

$title = $generate['title'];
Expand Down
2 changes: 1 addition & 1 deletion src/Actions/DuplicateTermAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ protected function generateTitleAndSlug(Term $term, $attempt = 1)
$slug .= '-' . $attempt;

// If the slug we've just built already exists, we'll try again, recursively.
if (TermAPI::findBySlug($slug, $term->taxonomy()->handle())) {
if (TermAPI::findByUri($slug, $term->taxonomy()->handle())) {
$generate = $this->generateTitleAndSlug($term, $attempt + 1);

$title = $generate['title'];
Expand Down
17 changes: 8 additions & 9 deletions tests/Actions/DuplicateEntryActionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
use DoubleThreeDigital\Duplicator\Actions\DuplicateEntryAction;
use DoubleThreeDigital\Duplicator\Tests\TestCase;
use Illuminate\Support\Facades\Config;
use Statamic\Facades\Entry;
use Statamic\Structures\CollectionStructure;

class DuplicateEntryActionTest extends TestCase
Expand Down Expand Up @@ -63,7 +62,7 @@ public function can_duplicate_entry()

$duplicate = $this->action->run(collect([$entry]), []);

$duplicateEntry = Entry::findBySlug('fresh-guide-1', 'guides');
$duplicateEntry = $this->findEntryBySlug('fresh-guide-1', 'guides');

$this->assertIsObject($duplicateEntry);
$this->assertSame($duplicateEntry->slug(), 'fresh-guide-1');
Expand All @@ -80,7 +79,7 @@ public function can_duplicate_entry_with_date()

$duplicate = $this->action->run(collect([$entry]), []);

$duplicateEntry = Entry::findBySlug('fresh-guide-smth-1', 'guides');
$duplicateEntry = $this->findEntryBySlug('fresh-guide-smth-1', 'guides');

$this->assertIsObject($duplicateEntry);
$this->assertSame($duplicateEntry->slug(), 'fresh-guide-smth-1');
Expand Down Expand Up @@ -117,7 +116,7 @@ public function can_duplicate_entry_with_original_parent()

$duplicate = $this->action->run(collect([$entry]), []);

$duplicateEntry = Entry::findBySlug('sausage-roll-1', 'recipies');
$duplicateEntry = $this->findEntryBySlug('sausage-roll-1', 'recipies');

// $this->assertIsObject($duplicateEntry);
// $this->assertSame($duplicateEntry->slug(), 'sausage-roll-duplicate');
Expand All @@ -144,7 +143,7 @@ public function can_duplicate_entry_with_config_publish_state()

$duplicate = $this->action->run(collect([$entry]), []);

$duplicateEntry = Entry::findBySlug('hello-world-1', 'blog');
$duplicateEntry = $this->findEntryBySlug('hello-world-1', 'blog');

$this->assertIsObject($duplicateEntry);
$this->assertSame($duplicateEntry->slug(), 'hello-world-1');
Expand All @@ -165,7 +164,7 @@ public function can_duplicate_entry_with_duplicated_entry_publish_state()

$duplicate = $this->action->run(collect([$entry]), []);

$duplicateEntry = Entry::findBySlug('hello-universe-1', 'blog');
$duplicateEntry = $this->findEntryBySlug('hello-universe-1', 'blog');

$this->assertIsObject($duplicateEntry);
$this->assertSame($duplicateEntry->slug(), 'hello-universe-1');
Expand All @@ -191,7 +190,7 @@ public function can_duplicate_entry_with_ignored_field()

$duplicate = $this->action->run(collect([$entry]), []);

$duplicateEntry = Entry::findBySlug('fresh-guide-1', 'guides');
$duplicateEntry = $this->findEntryBySlug('fresh-guide-1', 'guides');

$this->assertIsObject($duplicateEntry);
$this->assertSame($duplicateEntry->slug(), 'fresh-guide-1');
Expand All @@ -208,7 +207,7 @@ public function can_duplicate_entry_with_fingerprinting_enabled()

$duplicate = $this->action->run(collect([$entry]), []);

$duplicateEntry = Entry::findBySlug('new-guide-1', 'guides');
$duplicateEntry = $this->findEntryBySlug('new-guide-1', 'guides');

$this->assertIsObject($duplicateEntry);
$this->assertSame($duplicateEntry->slug(), 'new-guide-1');
Expand All @@ -226,7 +225,7 @@ public function can_duplicate_entry_with_fingerprinting_disabled()

$duplicate = $this->action->run(collect([$entry]), []);

$duplicateEntry = Entry::findBySlug('news-guide-1', 'guides');
$duplicateEntry = $this->findEntryBySlug('news-guide-1', 'guides');

$this->assertIsObject($duplicateEntry);
$this->assertSame($duplicateEntry->slug(), 'news-guide-1');
Expand Down
12 changes: 6 additions & 6 deletions tests/Actions/DuplicateTermActionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public function can_duplicate_term()

$duplicate = $this->action->run(collect([$term]), []);

$duplicateTerm = Term::findBySlug('haggis-1', 'categories');
$duplicateTerm = $this->findTermBySlug('haggis-1', 'categories');

$this->assertIsObject($duplicateTerm);
$this->assertSame($duplicateTerm->slug(), 'haggis-1');
Expand All @@ -79,7 +79,7 @@ public function can_duplicate_entry_with_config_publish_state()

$duplicate = $this->action->run(collect([$term]), []);

$duplicateTerm = Term::findBySlug('haggis-1', 'categories');
$duplicateTerm = $this->findTermBySlug('haggis-1', 'categories');

$this->assertIsObject($duplicateTerm);
$this->assertSame($duplicateTerm->slug(), 'haggis-1');
Expand All @@ -98,7 +98,7 @@ public function can_duplicate_entry_with_duplicated_entry_publish_state()

$duplicate = $this->action->run(collect([$term]), []);

$duplicateTerm = Term::findBySlug('haggis-1', 'categories');
$duplicateTerm = $this->findTermBySlug('haggis-1', 'categories');

$this->assertIsObject($duplicateTerm);
$this->assertSame($duplicateTerm->slug(), 'haggis-1');
Expand All @@ -124,7 +124,7 @@ public function can_duplicate_term_with_ignored_fields()

$duplicate = $this->action->run(collect([$term]), []);

$duplicateTerm = Term::findBySlug('haggis-1', 'categories');
$duplicateTerm = $this->findTermBySlug('haggis-1', 'categories');

$this->assertIsObject($duplicateTerm);
$this->assertSame($duplicateTerm->slug(), 'haggis-1');
Expand All @@ -141,7 +141,7 @@ public function can_duplicate_entry_with_fingerprinting_enabled()

$duplicate = $this->action->run(collect([$term]), []);

$duplicateTerm = Term::findBySlug('spaghetti-1', 'categories');
$duplicateTerm = $this->findTermBySlug('spaghetti-1', 'categories');

$this->assertIsObject($duplicateTerm);
$this->assertSame($duplicateTerm->slug(), 'spaghetti-1');
Expand All @@ -159,7 +159,7 @@ public function can_duplicate_entry_with_fingerprinting_disabled()

$duplicate = $this->action->run(collect([$term]), []);

$duplicateTerm = Term::findBySlug('cheese-1', 'categories');
$duplicateTerm = $this->findTermBySlug('cheese-1', 'categories');

$this->assertIsObject($duplicateTerm);
$this->assertSame($duplicateTerm->slug(), 'cheese-1');
Expand Down
18 changes: 16 additions & 2 deletions tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ public function makeEntry(string $collectionHandle, string $slug, AuthUser $user
->set('updated_at', now()->timestamp)
->save();

return Entry::findBySlug($slug, $collectionHandle);
return $this->findEntryBySlug($slug, $collectionHandle);
}

protected function makeTaxonomies(string $handle, string $name)
Expand All @@ -134,6 +134,20 @@ protected function makeTerm(string $taxonomyHandle, string $slug, AuthUser $user
])
->save();

return Term::findBySlug($slug, $taxonomyHandle);
return Term::findByUri($slug, $taxonomyHandle);
}

protected function findEntryBySlug(string $slug, string $collectionHandle)
{
return Entry::whereCollection($collectionHandle)
->where('slug', $slug)
->first();
}

protected function findTermBySlug(string $slug, string $taxonomyHandle)
{
return Term::whereTaxonomy($taxonomyHandle)
->where('slug', $slug)
->first();
}
}

0 comments on commit b3b1f03

Please sign in to comment.