Skip to content

Commit

Permalink
tests for include_modified_date
Browse files Browse the repository at this point in the history
  • Loading branch information
BrianHenryIE committed Nov 6, 2021
1 parent 0234bee commit e64eb70
Show file tree
Hide file tree
Showing 2 changed files with 97 additions and 4 deletions.
55 changes: 54 additions & 1 deletion tests/Unit/Composer/Extra/StraussConfigTest.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
/**
* Should accept Nannarl config and Mozart config.
* Should accept Strauss config and Mozart config.
*
* Should have sensible defaults.
*/
Expand All @@ -11,6 +11,9 @@
use Composer\IO\NullIO;
use PHPUnit\Framework\TestCase;

/**
* @covers \BrianHenryIE\Strauss\Composer\Extra\StraussConfig
*/
class StraussConfigTest extends TestCase
{

Expand Down Expand Up @@ -629,4 +632,54 @@ public function testNamespacePrefixHasNoSlash()

$this->assertEquals("My_Mozart_Config", $sut->getNamespacePrefix());
}

public function testIncludeModifiedDateDefaultTrue()
{

$composerExtraStraussJson = <<<'EOD'
{
"extra":{
"strauss": {
"namespace_prefix": "BrianHenryIE\\Strauss\\"
}
}
}
EOD;
$tmpfname = tempnam(sys_get_temp_dir(), 'strauss-test-');
file_put_contents($tmpfname, $composerExtraStraussJson);

$composer = Factory::create(new NullIO(), $tmpfname);

$sut = new StraussConfig($composer);

$this->assertTrue($sut->isIncludeModifiedDate());
}

/**
* "when I add "include_modified_date": false to the extra/strauss object it doesn't take any effect, the date is still added to the header."
*
* @see https://github.com/BrianHenryIE/strauss/issues/35
*/
public function testIncludeModifiedDate()
{

$composerExtraStraussJson = <<<'EOD'
{
"extra":{
"strauss": {
"namespace_prefix": "BrianHenryIE\\Strauss\\",
"include_modified_date": false
}
}
}
EOD;
$tmpfname = tempnam(sys_get_temp_dir(), 'strauss-test-');
file_put_contents($tmpfname, $composerExtraStraussJson);

$composer = Factory::create(new NullIO(), $tmpfname);

$sut = new StraussConfig($composer);

$this->assertFalse($sut->isIncludeModifiedDate());
}
}
46 changes: 43 additions & 3 deletions tests/Unit/LicenserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,6 @@ public function testFindLicenceFilesPathsAreRelative()
* @see https://www.phpliveregex.com/p/A5y
*/

// https://schibsted.com/blog/mocking-the-file-system-using-phpunit-and-vfsstream/


/**
* @see https://github.com/AuthorizeNet/sdk-php/blob/a3e76f96f674d16e892f87c58bedb99dada4b067/lib/net/authorize/api/contract/v1/ANetApiRequestType.php
*
Expand Down Expand Up @@ -106,6 +103,49 @@ public function testAppendHeaderCommentInformationNoHeader()
* @see https://github.com/BrianHenryIE/strauss
*/
namespace net\authorize\api\contract\v1;
EOD;

$actual = $sut->addChangeDeclarationToPhpString($given, '25-April-2021', 'proprietary');

$this->assertEquals($expected, $actual);
}


// https://schibsted.com/blog/mocking-the-file-system-using-phpunit-and-vfsstream/

/**
* Not including the date was reported as not working.
*
* @see https://github.com/BrianHenryIE/strauss/issues/35
*
* @covers ::addChangeDeclarationToPhpString
*/
public function testAppendHeaderCommentNoDate()
{

$author = 'BrianHenryIE';

$config = $this->createMock(StraussConfig::class);
$config->expects($this->once())->method('isIncludeModifiedDate')->willReturn(false);

$sut = new Licenser($config, __DIR__, array(), $author);

$given = <<<'EOD'
<?php
namespace net\authorize\api\contract\v1;
EOD;

$expected = <<<'EOD'
<?php
/**
* @license proprietary
*
* Modified by BrianHenryIE using Strauss.
* @see https://github.com/BrianHenryIE/strauss
*/
namespace net\authorize\api\contract\v1;
EOD;

Expand Down

0 comments on commit e64eb70

Please sign in to comment.