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

Statamic 5 Support #116

Merged
merged 18 commits into from
May 9, 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
18 changes: 9 additions & 9 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,22 @@ jobs:

strategy:
matrix:
php: [8.0, 8.1, 8.2]
laravel: [9.*, 10.*]
php: [8.1, 8.2, 8.3]
laravel: [10.*, 11.*]
stability: [prefer-lowest, prefer-stable]
os: [ubuntu-latest]
include:
- os: windows-latest
php: 8.1
laravel: 9.*
php: 8.3
laravel: 10.*
stability: prefer-stable
- os: windows-latest
php: 8.1
laravel: 10.*
php: 8.3
laravel: 11.*
stability: prefer-stable
exclude:
- php: 8.0
laravel: 10.*
- php: 8.1
laravel: 11.*

name: P${{ matrix.php }} - L${{ matrix.laravel }} - ${{ matrix.stability }} - ${{ matrix.os }}

Expand All @@ -52,7 +52,7 @@ jobs:

- name: Send Slack notification
uses: 8398a7/action-slack@v2
if: failure()
if: failure() && github.event_name == 'schedule'
with:
status: ${{ job.status }}
author_name: ${{ github.actor }}
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ composer.lock
.DS_Store
.phpunit.result.cache
.php-cs-fixer.cache
.phpunit.cache
8 changes: 4 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@
"name": "statamic/migrator",
"type": "statamic-addon",
"require": {
"friendsofphp/php-cs-fixer": "^3.16.0",
"friendsofphp/php-cs-fixer": "^3.54.0",
"league/flysystem-aws-s3-v3": "~1.0 || ~3.0",
"mustangostang/spyc": "dev-master#dfd9aadc1f5224065d55b42b712c7e99a50a3f4d"
},
"require-dev": {
"statamic/cms": "^4.0",
"statamic/cms": "^5.0",
"mockery/mockery": "^1.4.4",
"orchestra/testbench": "^7.0 || ^8.0",
"phpunit/phpunit": "^9.0"
"orchestra/testbench": "^8.0 || ^9.0",
"phpunit/phpunit": "^10.0"
},
"autoload": {
"psr-4": {
Expand Down
52 changes: 22 additions & 30 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -1,32 +1,24 @@
<?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">
<testsuites>
<testsuite name="Tests">
<directory suffix="Test.php">./tests</directory>
</testsuite>
</testsuites>
<filter>
<whitelist processUncoveredFilesFromWhitelist="true">
<directory suffix=".php">./src</directory>
</whitelist>
</filter>
<php>
<env name="APP_ENV" value="testing"/>
<env name="CACHE_DRIVER" value="array"/>
<env name="SESSION_DRIVER" value="array"/>
<env name="QUEUE_DRIVER" value="sync"/>
<env name="APP_URL" value="http://localhost/" />
<env name="APP_KEY" value="base64:QeU8nSJFKtBB3Y9SdxH0U4xH/1rsFd4zNfOLTeK/DUw=" />
<env name="DB_CONNECTION" value="sqlite"/>
<env name="DB_DATABASE" value=":memory:"/>
<env name="DISABLE_MIGRATOR_STATS" value="true" />
</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.5/phpunit.xsd" cacheDirectory=".phpunit.cache" backupStaticProperties="false">
<testsuites>
<testsuite name="Tests">
<directory suffix="Test.php">./tests</directory>
</testsuite>
</testsuites>
<php>
<env name="APP_ENV" value="testing"/>
<env name="CACHE_DRIVER" value="array"/>
<env name="SESSION_DRIVER" value="array"/>
<env name="QUEUE_DRIVER" value="sync"/>
<env name="APP_URL" value="http://localhost/"/>
<env name="APP_KEY" value="base64:QeU8nSJFKtBB3Y9SdxH0U4xH/1rsFd4zNfOLTeK/DUw="/>
<env name="DB_CONNECTION" value="sqlite"/>
<env name="DB_DATABASE" value=":memory:"/>
<env name="DISABLE_MIGRATOR_STATS" value="true"/>
</php>
<source>
<include>
<directory suffix=".php">./src</directory>
</include>
</source>
</phpunit>
11 changes: 7 additions & 4 deletions src/SettingsMigrator.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace Statamic\Migrator;

use Illuminate\Support\Facades\File;
use Statamic\Facades\Site;
use Statamic\Migrator\Exceptions\MigratorSkippedException;
use Statamic\Support\Arr;

Expand Down Expand Up @@ -116,12 +118,13 @@ protected function migrateRoutes()
*/
protected function migrateSystem()
{
$this->validate(['system.php', 'sites.php']);

$this->validate(['system.php']);
$system = $this->parseSettingsFile('system.yaml');

Configurator::file($configFile = 'statamic/sites.php')
->mergeSpaciously('sites', $this->migrateLocales($system))
Site::setSites($sites = $this->migrateLocales($system))->save();

Configurator::file($configFile = 'statamic/system.php')
->set('multisite', count($sites) > 1)
->ifNoChanges($this->throwNoChangesException($configFile));

return $this;
Expand Down
3 changes: 2 additions & 1 deletion src/YAML.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Statamic\Facades\File;
use Statamic\Facades\Pattern;
use Statamic\Facades\YAML as StatamicYAML;
use Statamic\Support\Arr;

class YAML
{
Expand Down Expand Up @@ -73,7 +74,7 @@ public static function spyc($str)
if (Pattern::startsWith($str, '---')) {
$split = preg_split("/\n---/", $str, 2, PREG_SPLIT_NO_EMPTY);
$str = $split[0];
$content = ltrim(array_get($split, 1, ''));
$content = ltrim(Arr::get($split, 1, ''));
}

$yaml = Spyc::YAMLLoadString($str);
Expand Down
8 changes: 4 additions & 4 deletions tests/ConfiguratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -638,13 +638,13 @@ protected function assertConfigFileContains($content)
$this->assertEquals('array', gettype(include $path));

// Assert begining and end of config is untouched.
$this->assertStringContainsString($beginning, $contents);
$this->assertStringContainsString($end, $contents);
$this->assertStringContainsStringWithNormalizedLineEndings($beginning, $contents);
$this->assertStringContainsStringWithNormalizedLineEndings($end, $contents);

// Assert irrelevant config is untouched.
$this->assertStringContainsString($extraConfig, $contents);
$this->assertStringContainsStringWithNormalizedLineEndings($extraConfig, $contents);

// Assert config file contains specific content.
return $this->assertStringContainsString($content, $contents);
return $this->assertStringContainsStringWithNormalizedLineEndings($content, $contents);
}
}
10 changes: 5 additions & 5 deletions tests/MigrateAssetContainerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -692,14 +692,14 @@ protected function assertFilesystemConfigFileContains($content)
$this->assertEquals('array', gettype(include $configPath));

// Assert begining and end of config is untouched.
$this->assertStringContainsString($beginning, $config);
$this->assertStringContainsString($end, $config);
$this->assertStringContainsStringWithNormalizedLineEndings($beginning, $config);
$this->assertStringContainsStringWithNormalizedLineEndings($end, $config);

// Assert irrelevant config is untouched.
$this->assertStringContainsString($irrelevantConfig, $config);
$this->assertStringContainsStringWithNormalizedLineEndings($irrelevantConfig, $config);

// Assert config file contains specific content.
return $this->assertStringContainsString($content, $config);
return $this->assertStringContainsStringWithNormalizedLineEndings($content, $config);
}

/**
Expand Down Expand Up @@ -731,7 +731,7 @@ protected function assertGitConfigPathExists($publicRelativePath)
{
$configPath = config_path('statamic/git.php');

$this->assertStringContainsString("public_path('{$publicRelativePath}')", $this->files->get($configPath));
$this->assertStringContainsStringWithNormalizedLineEndings("public_path('{$publicRelativePath}')", $this->files->get($configPath));

return $this->assertContains(public_path($publicRelativePath), Arr::get(include $configPath, 'paths'));
}
Expand Down
2 changes: 1 addition & 1 deletion tests/MigrateCollectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ public function it_migrates_number_ordered_collection($order)
$this->assertFileExists($this->collectionsPath('favs/purple-shirt.md'));
}

public function orderCollectionValues()
public static function orderCollectionValues()
{
return [
'number' => ['number'],
Expand Down
76 changes: 36 additions & 40 deletions tests/MigrateSettingsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Tests;

use Facades\Statamic\Console\Processes\Process;
use Illuminate\Support\Facades\File;

class MigrateSettingsTest extends TestCase
{
Expand Down Expand Up @@ -164,16 +165,15 @@ public function it_migrates_system_settings()
{
$this->artisan('statamic:migrate:settings', ['handle' => 'system']);

$this->assertConfigFileContains('sites.php', <<<'EOT'
'sites' => [
$this->assertSameWithNormalizedLineEndings(File::get(resource_path('sites.yaml')),
'default:
name: English
locale: en_US
url: /
');

'default' => [
'name' => 'English',
'locale' => 'en_US',
'url' => '/',
],

],
$this->assertConfigFileContains('system.php', <<<'EOT'
'multisite' => false,
EOT
);
}
Expand All @@ -196,24 +196,21 @@ public function it_migrates_multiple_locales_with_env_references()

$this->artisan('statamic:migrate:settings', ['handle' => 'system']);

$this->assertConfigFileContains('sites.php', <<<'EOT'
'sites' => [

'default' => [
'name' => 'English',
'locale' => 'en_US',
'url' => env('APP_URL'),
],

'fr' => [
'name' => 'French',
'locale' => 'fr_FR',
'url' => env('APP_URL_FR'),
],

],
$this->assertSameWithNormalizedLineEndings(File::get(resource_path('sites.yaml')),
"default:
name: English
locale: en_US
url: '{env:APP_URL}'
fr:
name: French
locale: fr_FR
url: '{env:APP_URL_FR}'
");

$this->assertConfigFileContains('system.php', <<<'EOT'
'multisite' => true,
EOT
);
);
}

/** @test */
Expand All @@ -223,16 +220,15 @@ public function it_migrates_missing_locales_using_v2_default()

$this->artisan('statamic:migrate:settings', ['handle' => 'system']);

$this->assertConfigFileContains('sites.php', <<<'EOT'
'sites' => [
$this->assertSameWithNormalizedLineEndings(File::get(resource_path('sites.yaml')),
'default:
name: English
locale: en_US
url: /
');

'default' => [
'name' => 'English',
'locale' => 'en_US',
'url' => '/',
],

],
$this->assertConfigFileContains('system.php', <<<'EOT'
'multisite' => false,
EOT
);
}
Expand Down Expand Up @@ -300,11 +296,11 @@ protected function assertConfigFileContains($file, $content)
$this->assertEquals('array', gettype(include $config));

// Assert begining and end of config is untouched.
$this->assertStringContainsString($beginning, $this->files->get($config));
$this->assertStringContainsString($end, $this->files->get($config));
$this->assertStringContainsStringWithNormalizedLineEndings($beginning, $this->files->get($config));
$this->assertStringContainsStringWithNormalizedLineEndings($end, $this->files->get($config));

// Assert config file contains specific content.
return $this->assertStringContainsString($content, $this->files->get($config));
return $this->assertStringContainsStringWithNormalizedLineEndings($content, $this->files->get($config));
}

/**
Expand All @@ -325,9 +321,9 @@ protected function assertRoutesFileContains($content)
$end = '];';

// Assert begining of routes file is untouched.
$this->assertStringContainsString($beginning, $contents);
$this->assertStringContainsStringWithNormalizedLineEndings($beginning, $contents);

// Assert routes file contains specific content.
return $this->assertStringContainsString($content, $contents);
return $this->assertStringContainsStringWithNormalizedLineEndings($content, $contents);
}
}
4 changes: 2 additions & 2 deletions tests/RouterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -155,10 +155,10 @@ protected function assertRoutesFileContains($content)
EOT;

// Assert begining of routes file is untouched.
$this->assertStringContainsString($beginning, $contents);
$this->assertStringContainsStringWithNormalizedLineEndings($beginning, $contents);

// Assert routes file contains specific content.
return $this->assertStringContainsString($content, $contents);
return $this->assertStringContainsStringWithNormalizedLineEndings($content, $contents);
}

/**
Expand Down
20 changes: 16 additions & 4 deletions tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -122,14 +122,14 @@ protected function assertContainsIgnoringLineEndings($expected, $actual)
{
$actual = str_replace("\r\n", "\n", $actual);

$this->assertStringContainsString($expected, $actual);
$this->assertStringContainsStringWithNormalizedLineEndings($expected, $actual);
}

protected function assertFileHasContent($expected, $path)
{
$this->assertFileExists($path);

$this->assertStringContainsString($expected, $this->files->get($path));
$this->assertStringContainsStringWithNormalizedLineEndings($expected, $this->files->get($path));
}

protected function sitePath($append = null)
Expand All @@ -145,9 +145,21 @@ protected static function normalizeMultilineString($string)
/**
* Normalize line endings before performing assertion in windows.
*/
public static function assertStringContainsString($needle, $haystack, $message = ''): void
public static function assertStringContainsStringWithNormalizedLineEndings($needle, $haystack, $message = ''): void
{
parent::assertStringContainsString(
static::assertStringContainsString(
static::normalizeMultilineString($needle),
static::normalizeMultilineString($haystack),
$message
);
}

/**
* Normalize line endings before performing assertion in windows.
*/
public static function assertSameWithNormalizedLineEndings($needle, $haystack, $message = ''): void
{
static::assertSame(
static::normalizeMultilineString($needle),
static::normalizeMultilineString($haystack),
$message
Expand Down