Skip to content

Commit

Permalink
Switched to composer 2 in ci for Silverstripe 5.2/PHP 8.1
Browse files Browse the repository at this point in the history
Updated code style
  • Loading branch information
UndefinedOffset committed May 16, 2024
1 parent cc76997 commit 9700d29
Show file tree
Hide file tree
Showing 7 changed files with 151 additions and 131 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ jobs:
extensions: ${{ env.php_extensions }}
ini-values: log_errors=On, error_log="${{github.workspace}}/artifacts/php_errors.log"
coverage: none
tools: composer:v1
tools: composer:v2

- name: Get composer cache directory
id: composer-cache
Expand Down
66 changes: 43 additions & 23 deletions phpcs.xml.dist
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
<?xml version="1.0" encoding="UTF-8"?>
<ruleset name="SilverStripe">
<description>CodeSniffer ruleset for SilverStripe coding conventions.</description>

<!-- base rules are PSR-2 -->
<rule ref="PSR2" >
<!-- Current exclusions -->
<exclude name="PSR1.Methods.CamelCapsMethodName" />
<exclude name="PSR1.Files.SideEffects.FoundWithSymbols" />
<exclude name="PSR2.Classes.PropertyDeclaration" />
<exclude name="PSR2.Methods.MethodDeclaration.Underscore" />
<exclude name="Squiz.Scope.MethodScope" />
<exclude name="Squiz.Classes.ValidClassName.NotCamelCaps" />
<exclude name="Generic.Files.LineLength.TooLong" />
<exclude name="PEAR.Functions.ValidDefaultValue.NotAtEnd" />
<description>CodeSniffer ruleset for SilverStripe coding conventions.</description>

<!-- base rules are PSR-2 -->
<rule ref="PSR2" >
<!-- Current exclusions -->
<exclude name="PSR1.Methods.CamelCapsMethodName" />
<exclude name="PSR1.Files.SideEffects.FoundWithSymbols" />
<exclude name="PSR2.Classes.PropertyDeclaration" />
<exclude name="PSR2.Methods.MethodDeclaration.Underscore" />
<exclude name="Squiz.Scope.MethodScope" />
<exclude name="Squiz.Classes.ValidClassName.NotCamelCaps" />
<exclude name="Generic.Files.LineLength.TooLong" />
<exclude name="PEAR.Functions.ValidDefaultValue.NotAtEnd" />
<exclude name="PSR2.ControlStructures.ElseIfDeclaration" />
</rule>
</rule>

<rule ref="Squiz.Strings.ConcatenationSpacing">
<properties>
<property name="spacing" value="1" />
<property name="ignoreNewlines" value="true"/>
</properties>
</rule>
<rule ref="Squiz.Strings.ConcatenationSpacing">
<properties>
<property name="spacing" value="1" />
<property name="ignoreNewlines" value="true"/>
</properties>
</rule>

<rule ref="PEAR.ControlStructures.MultiLineCondition" />

Expand All @@ -37,10 +37,30 @@
</properties>
</rule>

<rule ref="PSR12.Functions.ReturnTypeDeclaration" />
<rule ref="PSR12.Files.OpenTag" />

<rule ref="Squiz.ControlStructures.ElseIfDeclaration" />

<rule ref="PSR12.Functions.ReturnTypeDeclaration" />

<rule ref="PSR12.Classes.OpeningBraceSpace" />
<rule ref="Squiz.WhiteSpace.FunctionOpeningBraceSpace" />

<rule ref="Squiz.Commenting.InlineComment.NoSpaceBefore">
<type>warning</type>
</rule>
<rule ref="Squiz.Commenting.InlineComment.TabBefore">
<type>warning</type>
</rule>
<rule ref="Squiz.Commenting.InlineComment.WrongStyle">
<type>warning</type>
</rule>
<rule ref="Squiz.Commenting.InlineComment.Empty">
<type>warning</type>
</rule>

<!-- include php files only -->
<arg name="extensions" value="php,lib,inc,php5"/>
<!-- include php files only -->
<arg name="extensions" value="php,lib,inc,php5"/>

<file>./src</file>
<file>./tests</file>
Expand Down
2 changes: 1 addition & 1 deletion src/Extensions/ImageExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public function getIsWebP()
*/
public function getWebP()
{
//Do nothing we aleady appear to have a webp
// Do nothing we aleady appear to have a webp
if ($this->owner->getIsWebP()) {
return $this->owner;
}
Expand Down
2 changes: 1 addition & 1 deletion tests/PHPUnit/Bootstrap/GitHubActionsAnnotatorPrinter.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ protected function relativePath($path)
{
$relative = str_replace(getcwd() . DIRECTORY_SEPARATOR, '', $path);

//Normalize
// Normalize
$relative = str_replace('\\', '/', $relative);

return $relative;
Expand Down
82 changes: 41 additions & 41 deletions tests/PHPUnit/GenerateWebP.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,24 +58,24 @@ public function testWebPDetection()
/** @var Image|\WebbuildersGroup\NextGenImages\Extensions\ImageExtension $png **/
$png = $this->objFromFixture(Image::class, 'testpng');

//Sanity Check
// Sanity Check
$this->assertNotEmpty($png);
$this->assertNotFalse($png);
$this->assertTrue($png->exists());

//Make srue the image was not detected as a WebP
// Make srue the image was not detected as a WebP
$this->assertFalse($png->getIsWebP(), 'Image should not have been a WebP but it was detected as one');


/** @var Image|\WebbuildersGroup\NextGenImages\Extensions\ImageExtension $webp **/
$webp = $this->objFromFixture(Image::class, 'testwebp');

//Sanity Check
// Sanity Check
$this->assertNotEmpty($webp);
$this->assertNotFalse($webp);
$this->assertTrue($webp->exists());

//Make sure the image was detected as a WebP
// Make sure the image was detected as a WebP
$this->assertTrue($webp->getIsWebP(), 'Image should have been a WebP but it wasn\'t detected as one');
}

Expand All @@ -87,18 +87,18 @@ public function testImageGetWebP()
/** @var Image|\WebbuildersGroup\NextGenImages\Extensions\ImageExtension $img **/
$img = $this->objFromFixture(Image::class, 'testpng');

//Sanity Check
// Sanity Check
$this->assertNotEmpty($img);
$this->assertNotFalse($img);
$this->assertTrue($img->exists());


//Attempt to generate the WebP
// Attempt to generate the WebP
$generatedWebP = $img->getWebP();
$this->assertInstanceOf(DBFile::class, $generatedWebP);


//Check to see if the file was generated how we expect
// Check to see if the file was generated how we expect
$this->assertFileExists(TestAssetStore::base_path() . '/folder/wbg-logo-png__ExtRewriteWyJwbmciLCJ3ZWJwIl0.webp', 'WebP Variant was not generated as expected');
}

Expand All @@ -110,25 +110,25 @@ public function testDBFileGetWebP()
/** @var Image|\WebbuildersGroup\NextGenImages\Extensions\ImageExtension $img **/
$img = $this->objFromFixture(Image::class, 'testpng');

//Sanity Check
// Sanity Check
$this->assertNotEmpty($img);
$this->assertNotFalse($img);
$this->assertTrue($img->exists());


//Create a DBFile of the image
// Create a DBFile of the image
/** @var DBFile|\WebbuildersGroup\NextGenImages\Extensions\ImageExtension $dbFile **/
$dbFile = $img->File;
$this->assertInstanceOf(DBFile::class, $dbFile);
$this->assertEquals('folder/wbg-logo-png.png', $dbFile->Filename);


//Attempt to generate the WebP
// Attempt to generate the WebP
$generatedWebP = $dbFile->getWebP();
$this->assertInstanceOf(DBFile::class, $generatedWebP);


//Check to see if the file was generated how we expect
// Check to see if the file was generated how we expect
$this->assertFileExists(TestAssetStore::base_path() . '/folder/wbg-logo-png__ExtRewriteWyJwbmciLCJ3ZWJwIl0.webp', 'WebP Variant was not generated as expected');
}

Expand All @@ -140,26 +140,26 @@ public function testImageResampleGeneratedWebP()
/** @var Image|\WebbuildersGroup\NextGenImages\Extensions\ImageExtension $img **/
$img = $this->objFromFixture(Image::class, 'testpng');

//Sanity Check
// Sanity Check
$this->assertNotEmpty($img);
$this->assertNotFalse($img);
$this->assertTrue($img->exists());

//Generate the WebP
// Generate the WebP
$generatedWebP = $img->getWebP();


//Resample the WebP
// Resample the WebP
/** @var DBFile|\WebbuildersGroup\NextGenImages\Extensions\ImageExtension $resampled **/
$resampled = $generatedWebP->ScaleWidth(100);
$this->assertInstanceOf(DBFile::class, $resampled);


//Make sure we got a resample back
// Make sure we got a resample back
$this->assertEquals('ExtRewriteWyJwbmciLCJ3ZWJwIl0_ScaleWidthWzEwMF0', $resampled->getVariant());


//Make sure the resample has the name we expect
// Make sure the resample has the name we expect
$this->assertEquals('/assets/GenerateWebPTest/folder/wbg-logo-png__ExtRewriteWyJwbmciLCJ3ZWJwIl0_ScaleWidthWzEwMF0.webp', $resampled->getURL(false));
}

Expand All @@ -171,28 +171,28 @@ public function testDBFileResampleGeneratedWebP()
/** @var Image|\WebbuildersGroup\NextGenImages\Extensions\ImageExtension $img **/
$img = $this->objFromFixture(Image::class, 'testpng');

//Sanity Check
// Sanity Check
$this->assertNotEmpty($img);
$this->assertNotFalse($img);
$this->assertTrue($img->exists());

$dbFile = $img->File;

//Generate the WebP
// Generate the WebP
$generatedWebP = $dbFile->getWebP();


//Resample the WebP
// Resample the WebP
/** @var DBFile|\WebbuildersGroup\NextGenImages\Extensions\ImageExtension $resampled **/
$resampled = $generatedWebP->ScaleWidth(100);
$this->assertInstanceOf(DBFile::class, $resampled);


//Make sure we got a resample back
// Make sure we got a resample back
$this->assertEquals('ExtRewriteWyJwbmciLCJ3ZWJwIl0_ScaleWidthWzEwMF0', $resampled->getVariant());


//Make sure the resample has the name we expect
// Make sure the resample has the name we expect
$this->assertEquals('/assets/GenerateWebPTest/folder/wbg-logo-png__ExtRewriteWyJwbmciLCJ3ZWJwIl0_ScaleWidthWzEwMF0.webp', $resampled->getURL(false));
}

Expand All @@ -204,34 +204,34 @@ public function testImageResampleResampleGetWebP()
/** @var Image|\WebbuildersGroup\NextGenImages\Extensions\ImageExtension $img **/
$img = $this->objFromFixture(Image::class, 'testpng');

//Sanity Check
// Sanity Check
$this->assertNotEmpty($img);
$this->assertNotFalse($img);
$this->assertTrue($img->exists());


//Resample the original
// Resample the original
/** @var DBFile|\WebbuildersGroup\NextGenImages\Extensions\ImageExtension $resampled **/
$resampled = $img->ScaleWidth(100);
$this->assertInstanceOf(DBFile::class, $resampled);


//Make sure we got a resample back
// Make sure we got a resample back
$this->assertEquals('ScaleWidthWzEwMF0', $resampled->getVariant());

//Make sure the resample has the name we expect
// Make sure the resample has the name we expect
$this->assertEquals('/assets/GenerateWebPTest/folder/wbg-logo-png__ScaleWidthWzEwMF0.png', $resampled->getURL(false));


//Generate the WebP
// Generate the WebP
$generatedWebP = $resampled->getWebP();


//Make sure we got a resample back
// Make sure we got a resample back
$this->assertEquals('ScaleWidthWzEwMF0_ExtRewriteWyJwbmciLCJ3ZWJwIl0', $generatedWebP->getVariant());


//Make sure the resample has the name we expect
// Make sure the resample has the name we expect
$this->assertEquals('/assets/GenerateWebPTest/folder/wbg-logo-png__ScaleWidthWzEwMF0_ExtRewriteWyJwbmciLCJ3ZWJwIl0.webp', $generatedWebP->getURL(false));
}

Expand All @@ -243,36 +243,36 @@ public function testDBFileResampleGetWebP()
/** @var Image|\WebbuildersGroup\NextGenImages\Extensions\ImageExtension $img **/
$img = $this->objFromFixture(Image::class, 'testpng');

//Sanity Check
// Sanity Check
$this->assertNotEmpty($img);
$this->assertNotFalse($img);
$this->assertTrue($img->exists());

$dbFile = $img->File;


//Resample the original
// Resample the original
/** @var DBFile|\WebbuildersGroup\NextGenImages\Extensions\ImageExtension $resampled **/
$resampled = $dbFile->ScaleWidth(100);
$this->assertInstanceOf(DBFile::class, $resampled);


//Make sure we got a resample back
// Make sure we got a resample back
$this->assertEquals('ScaleWidthWzEwMF0', $resampled->getVariant());

//Make sure the resample has the name we expect
// Make sure the resample has the name we expect
$this->assertEquals('/assets/GenerateWebPTest/folder/wbg-logo-png__ScaleWidthWzEwMF0.png', $resampled->getURL(false));


//Generate the WebP
// Generate the WebP
$generatedWebP = $resampled->getWebP();


//Make sure we got a resample back
// Make sure we got a resample back
$this->assertEquals('ScaleWidthWzEwMF0_ExtRewriteWyJwbmciLCJ3ZWJwIl0', $generatedWebP->getVariant());


//Make sure the resample has the name we expect
// Make sure the resample has the name we expect
$this->assertEquals('/assets/GenerateWebPTest/folder/wbg-logo-png__ScaleWidthWzEwMF0_ExtRewriteWyJwbmciLCJ3ZWJwIl0.webp', $generatedWebP->getURL(false));
}

Expand All @@ -284,15 +284,15 @@ public function testImageGenerateWebPWithWebP()
/** @var Image|\WebbuildersGroup\NextGenImages\Extensions\ImageExtension $img **/
$img = $this->objFromFixture(Image::class, 'testwebp');

//Sanity Check
// Sanity Check
$this->assertNotEmpty($img);
$this->assertNotFalse($img);
$this->assertTrue($img->exists());

//Generate the WebP
// Generate the WebP
$generatedWebP = $img->getWebP();

//Make sure we got an image back again and that it's the same image
// Make sure we got an image back again and that it's the same image
$this->assertInstanceOf(Image::class, $generatedWebP);
$this->assertEquals($img->ID, $generatedWebP->ID);
$this->assertEquals($img->getURL(), $generatedWebP->getURL());
Expand All @@ -306,17 +306,17 @@ public function testDBFileGenerateWebPWithWebP()
/** @var Image|\WebbuildersGroup\NextGenImages\Extensions\ImageExtension $img **/
$img = $this->objFromFixture(Image::class, 'testwebp');

//Sanity Check
// Sanity Check
$this->assertNotEmpty($img);
$this->assertNotFalse($img);
$this->assertTrue($img->exists());

$img = $img->File;

//Generate the WebP
// Generate the WebP
$generatedWebP = $img->getWebP();

//Make sure we got an image back again and that it's the same image
// Make sure we got an image back again and that it's the same image
$this->assertInstanceOf(DBFile::class, $generatedWebP);
$this->assertEquals($img->getURL(), $generatedWebP->getURL());
}
Expand Down
Loading

0 comments on commit 9700d29

Please sign in to comment.