Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into pr/laravel-shift/459
Browse files Browse the repository at this point in the history
  • Loading branch information
mikebronner authored Mar 2, 2024
2 parents c90c9c5 + eda274d commit 78201e3
Show file tree
Hide file tree
Showing 6 changed files with 114 additions and 16 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/laravel.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ jobs:
with:
postgresql version: '15'
postgresql db: 'testing'
postgresql user: 'homestead'
postgresql user: 'forge'
postgresql password: 'secret'

- name: Remove Nova on a pull request
Expand All @@ -56,7 +56,7 @@ jobs:

- name: Install Dependencies
run: |
composer config "http-basic.nova.laravel.com" "${{ secrets.NOVA_USERNAME }}" "${{ secrets.NOVA_PASSWORD }}"
composer config "http-basic.nova.laravel.com" "${{ secrets.NOVA_USERNAME }}" "${{ secrets.NOVA_LICENSE_KEY }}"
composer install -q --no-ansi --no-interaction --no-scripts --no-suggest --no-progress --prefer-dist
- name: Execute Integration and Feature tests via PHPUnit
Expand Down
43 changes: 43 additions & 0 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit
backupGlobals="false"
backupStaticProperties="false"
bootstrap="vendor/autoload.php"
cacheDirectory=".phpunit.cache"
colors="true"
processIsolation="false"
stopOnFailure="true"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.5/phpunit.xsd"
>
<testsuites>
<testsuite name="Feature">
<directory suffix="Test.php">./tests/Feature</directory>
</testsuite>
<testsuite name="Integration">
<directory suffix="Test.php">./tests/Integration</directory>
</testsuite>
<testsuite name="Nova">
<directory suffix="Test.php">./tests/Nova</directory>
</testsuite>
</testsuites>
<php>
<server name="APP_ENV" value="testing"/>
<server name="APP_KEY" value="base64:Xgs1LQt1GdVHhD6qyYCXnyq61DE3UKqJ5k2SJc+Nw2g="/>
<server name="APP_URL" value="http://localhost"/>
<server name="CACHE_DRIVER" value="redis"/>
<server name="DB_CONNECTION" value="sqlite"/>
<server name="DB_DATABASE" value=":memory:"/>
<server name="DB_PASSWORD" value="secret"/>
<server name="DB_USERNAME" value="homestead"/>
<server name="PGSQL_HOST" value="127.0.0.1"/>
<server name="QUEUE_DRIVER" value="sync"/>
<server name="REDIS_HOST" value="127.0.0.1"/>
<server name="SESSION_DRIVER" value="array"/>
</php>
<source>
<include>
<directory suffix=".php">./src</directory>
</include>
</source>
</phpunit>
16 changes: 12 additions & 4 deletions src/Traits/Caching.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public function applyScopes()
if ($this->scopesAreApplied) {
return $this;
}

return parent::applyScopes();
}

Expand Down Expand Up @@ -170,7 +170,7 @@ protected function makeCacheKey(
?? Container::getInstance()
->make("db")
->query();

if (
$this->query
&& method_exists($this->query, "getQuery")
Expand Down Expand Up @@ -263,6 +263,10 @@ protected function checkCooldownAndRemoveIfExpired(Model $instance)

protected function checkCooldownAndFlushAfterPersisting(Model $instance, string $relationship = "")
{
if (! $this->isCachable()) {
return;
}

[$cacheCooldown, $invalidatedAt] = $instance->getModelCacheCooldown($instance);

if (! $cacheCooldown) {
Expand Down Expand Up @@ -295,6 +299,11 @@ public function isCachable() : bool
$isCacheDisabled = ! Container::getInstance()
->make("config")
->get("laravel-model-caching.enabled");

if ($isCacheDisabled) {
return false;
}

$allRelationshipsAreCachable = true;

if (
Expand All @@ -311,7 +320,7 @@ public function isCachable() : bool
) {
return $carry;
}

$relatedModel = $this->model->$related()->getRelated();

if (
Expand All @@ -327,7 +336,6 @@ public function isCachable() : bool
}

return $this->isCachable
&& ! $isCacheDisabled
&& $allRelationshipsAreCachable;
}

Expand Down
16 changes: 12 additions & 4 deletions tests/CreatesApplication.php
Original file line number Diff line number Diff line change
Expand Up @@ -139,18 +139,26 @@ protected function getEnvironmentSetUp($app)
]);
}

public function appVersionEightAndUp(): bool
public function appVersionEightAndNine(): bool
{
return version_compare(app()->version(), '8.0.0', '>=');
return version_compare(app()->version(), '8.0.0', '>=')
&& version_compare(app()->version(), '10.0.0', '<');
}

public function appVersionFiveBetweenSeven(): bool
{
return version_compare(app()->version(), '5.6.0', '>=') && version_compare(app()->version(), '8.0.0', '<');
return version_compare(app()->version(), '5.6.0', '>=')
&& version_compare(app()->version(), '8.0.0', '<');
}

public function appVersionOld(): bool
{
return version_compare(app()->version(), '5.4.0', '>=') && version_compare(app()->version(), '5.6.0', '<');
return version_compare(app()->version(), '5.4.0', '>=')
&& version_compare(app()->version(), '5.6.0', '<');
}

public function appVersionTen(): bool
{
return version_compare(app()->version(), '10.0.0', '>=');
}
}
24 changes: 21 additions & 3 deletions tests/Feature/PaginationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,14 @@ class PaginationTest extends FeatureTestCase
{
public function testPaginationProvidesDifferentLinksOnDifferentPages()
{
// Checking the version start with 10.0.
if ($this->appVersionTen()) {
$page1ActiveLink = '<span class="relative inline-flex items-center px-4 py-2 -ml-px text-sm font-medium text-gray-500 bg-white border border-gray-300 cursor-default leading-5 dark:bg-gray-800 dark:border-gray-600">1</span>';
$page2ActiveLink = '<span class="relative inline-flex items-center px-4 py-2 -ml-px text-sm font-medium text-gray-500 bg-white border border-gray-300 cursor-default leading-5 dark:bg-gray-800 dark:border-gray-600">2</span>';
}

// Checking the version start with 8.0.
if ($this->appVersionEightAndUp()) {
if ($this->appVersionEightAndNine()) {
$page1ActiveLink = '<span class="relative inline-flex items-center px-4 py-2 -ml-px text-sm font-medium text-gray-500 bg-white border border-gray-300 cursor-default leading-5">1</span>';
$page2ActiveLink = '<span class="relative inline-flex items-center px-4 py-2 -ml-px text-sm font-medium text-gray-500 bg-white border border-gray-300 cursor-default leading-5">2</span>';
}
Expand Down Expand Up @@ -39,8 +45,14 @@ public function testPaginationProvidesDifferentLinksOnDifferentPages()

public function testAdvancedPagination()
{
// Checking the version start with 10.0.
if ($this->appVersionTen()) {
$page1ActiveLink = '<span class="relative inline-flex items-center px-4 py-2 -ml-px text-sm font-medium text-gray-500 bg-white border border-gray-300 cursor-default leading-5 dark:bg-gray-800 dark:border-gray-600">1</span>';
$page2ActiveLink = '<span class="relative inline-flex items-center px-4 py-2 -ml-px text-sm font-medium text-gray-500 bg-white border border-gray-300 cursor-default leading-5 dark:bg-gray-800 dark:border-gray-600">2</span>';
}

// Checking the version start with 8.0.
if ($this->appVersionEightAndUp()) {
if ($this->appVersionEightAndNine()) {
$page1ActiveLink = '<span class="relative inline-flex items-center px-4 py-2 -ml-px text-sm font-medium text-gray-500 bg-white border border-gray-300 cursor-default leading-5">1</span>';
$page2ActiveLink = '<span class="relative inline-flex items-center px-4 py-2 -ml-px text-sm font-medium text-gray-500 bg-white border border-gray-300 cursor-default leading-5">2</span>';
}
Expand All @@ -62,8 +74,14 @@ public function testAdvancedPagination()

public function testCustomPagination()
{
// Checking the version start with 10.0.
if ($this->appVersionTen()) {
$page1ActiveLink = '<span class="relative inline-flex items-center px-4 py-2 -ml-px text-sm font-medium text-gray-500 bg-white border border-gray-300 cursor-default leading-5 dark:bg-gray-800 dark:border-gray-600">1</span>';
$page2ActiveLink = '<span class="relative inline-flex items-center px-4 py-2 -ml-px text-sm font-medium text-gray-500 bg-white border border-gray-300 cursor-default leading-5 dark:bg-gray-800 dark:border-gray-600">2</span>';
}

// Checking the version start with 8.0.
if ($this->appVersionEightAndUp()) {
if ($this->appVersionEightAndNine()) {
$page1ActiveLink = '<span class="relative inline-flex items-center px-4 py-2 -ml-px text-sm font-medium text-gray-500 bg-white border border-gray-300 cursor-default leading-5">1</span>';
$page2ActiveLink = '<span class="relative inline-flex items-center px-4 py-2 -ml-px text-sm font-medium text-gray-500 bg-white border border-gray-300 cursor-default leading-5">2</span>';
}
Expand Down
27 changes: 24 additions & 3 deletions tests/Integration/CachedBuilder/PaginateTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,14 @@ public function testPaginationIsCached()

public function testPaginationReturnsCorrectLinks()
{
if ($this->appVersionEightAndUp()) {
// Checking the version start with 10.0.
if ($this->appVersionTen()) {
$page1ActiveLink = '<span class="relative inline-flex items-center px-4 py-2 -ml-px text-sm font-medium text-gray-500 bg-white border border-gray-300 cursor-default leading-5 dark:bg-gray-800 dark:border-gray-600">1</span>';
$page2ActiveLink = '<span class="relative inline-flex items-center px-4 py-2 -ml-px text-sm font-medium text-gray-500 bg-white border border-gray-300 cursor-default leading-5 dark:bg-gray-800 dark:border-gray-600">2</span>';
$page24ActiveLink = '<span class="relative inline-flex items-center px-4 py-2 -ml-px text-sm font-medium text-gray-500 bg-white border border-gray-300 cursor-default leading-5 dark:bg-gray-800 dark:border-gray-600">24</span>';
}

if ($this->appVersionEightAndNine()) {
$page1ActiveLink = '<span class="relative inline-flex items-center px-4 py-2 -ml-px text-sm font-medium text-gray-500 bg-white border border-gray-300 cursor-default leading-5">1</span>';
$page2ActiveLink = '<span class="relative inline-flex items-center px-4 py-2 -ml-px text-sm font-medium text-gray-500 bg-white border border-gray-300 cursor-default leading-5">2</span>';
$page24ActiveLink = '<span class="relative inline-flex items-center px-4 py-2 -ml-px text-sm font-medium text-gray-500 bg-white border border-gray-300 cursor-default leading-5">24</span>';
Expand Down Expand Up @@ -71,7 +78,14 @@ public function testPaginationReturnsCorrectLinks()

public function testPaginationWithOptionsReturnsCorrectLinks()
{
if ($this->appVersionEightAndUp()) {
// Checking the version start with 10.0.
if ($this->appVersionTen()) {
$page1ActiveLink = '<span class="relative inline-flex items-center px-4 py-2 -ml-px text-sm font-medium text-gray-500 bg-white border border-gray-300 cursor-default leading-5 dark:bg-gray-800 dark:border-gray-600">1</span>';
$page2ActiveLink = '<span class="relative inline-flex items-center px-4 py-2 -ml-px text-sm font-medium text-gray-500 bg-white border border-gray-300 cursor-default leading-5 dark:bg-gray-800 dark:border-gray-600">2</span>';
$page24ActiveLink = '<span class="relative inline-flex items-center px-4 py-2 -ml-px text-sm font-medium text-gray-500 bg-white border border-gray-300 cursor-default leading-5 dark:bg-gray-800 dark:border-gray-600">24</span>';
}

if ($this->appVersionEightAndNine()) {
$page1ActiveLink = '<span class="relative inline-flex items-center px-4 py-2 -ml-px text-sm font-medium text-gray-500 bg-white border border-gray-300 cursor-default leading-5">1</span>';
$page2ActiveLink = '<span class="relative inline-flex items-center px-4 py-2 -ml-px text-sm font-medium text-gray-500 bg-white border border-gray-300 cursor-default leading-5">2</span>';
$page24ActiveLink = '<span class="relative inline-flex items-center px-4 py-2 -ml-px text-sm font-medium text-gray-500 bg-white border border-gray-300 cursor-default leading-5">24</span>';
Expand Down Expand Up @@ -106,7 +120,14 @@ public function testPaginationWithOptionsReturnsCorrectLinks()

public function testPaginationWithCustomOptionsReturnsCorrectLinks()
{
if ($this->appVersionEightAndUp()) {
// Checking the version start with 10.0.
if ($this->appVersionTen()) {
$page1ActiveLink = '<span class="relative inline-flex items-center px-4 py-2 -ml-px text-sm font-medium text-gray-500 bg-white border border-gray-300 cursor-default leading-5 dark:bg-gray-800 dark:border-gray-600">1</span>';
$page2ActiveLink = '<span class="relative inline-flex items-center px-4 py-2 -ml-px text-sm font-medium text-gray-500 bg-white border border-gray-300 cursor-default leading-5 dark:bg-gray-800 dark:border-gray-600">2</span>';
$page24ActiveLink = '<span class="relative inline-flex items-center px-4 py-2 -ml-px text-sm font-medium text-gray-500 bg-white border border-gray-300 cursor-default leading-5 dark:bg-gray-800 dark:border-gray-600">24</span>';
}

if ($this->appVersionEightAndNine()) {
$page1ActiveLink = '<span class="relative inline-flex items-center px-4 py-2 -ml-px text-sm font-medium text-gray-500 bg-white border border-gray-300 cursor-default leading-5">1</span>';
$page2ActiveLink = '<span class="relative inline-flex items-center px-4 py-2 -ml-px text-sm font-medium text-gray-500 bg-white border border-gray-300 cursor-default leading-5">2</span>';
$page24ActiveLink = '<span class="relative inline-flex items-center px-4 py-2 -ml-px text-sm font-medium text-gray-500 bg-white border border-gray-300 cursor-default leading-5">24</span>';
Expand Down

0 comments on commit 78201e3

Please sign in to comment.