Skip to content

Commit e64eb70

Browse files
committed
tests for include_modified_date
1 parent 0234bee commit e64eb70

File tree

2 files changed

+97
-4
lines changed

2 files changed

+97
-4
lines changed

tests/Unit/Composer/Extra/StraussConfigTest.php

Lines changed: 54 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22
/**
3-
* Should accept Nannarl config and Mozart config.
3+
* Should accept Strauss config and Mozart config.
44
*
55
* Should have sensible defaults.
66
*/
@@ -11,6 +11,9 @@
1111
use Composer\IO\NullIO;
1212
use PHPUnit\Framework\TestCase;
1313

14+
/**
15+
* @covers \BrianHenryIE\Strauss\Composer\Extra\StraussConfig
16+
*/
1417
class StraussConfigTest extends TestCase
1518
{
1619

@@ -629,4 +632,54 @@ public function testNamespacePrefixHasNoSlash()
629632

630633
$this->assertEquals("My_Mozart_Config", $sut->getNamespacePrefix());
631634
}
635+
636+
public function testIncludeModifiedDateDefaultTrue()
637+
{
638+
639+
$composerExtraStraussJson = <<<'EOD'
640+
{
641+
"extra":{
642+
"strauss": {
643+
"namespace_prefix": "BrianHenryIE\\Strauss\\"
644+
}
645+
}
646+
}
647+
EOD;
648+
$tmpfname = tempnam(sys_get_temp_dir(), 'strauss-test-');
649+
file_put_contents($tmpfname, $composerExtraStraussJson);
650+
651+
$composer = Factory::create(new NullIO(), $tmpfname);
652+
653+
$sut = new StraussConfig($composer);
654+
655+
$this->assertTrue($sut->isIncludeModifiedDate());
656+
}
657+
658+
/**
659+
* "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."
660+
*
661+
* @see https://github.com/BrianHenryIE/strauss/issues/35
662+
*/
663+
public function testIncludeModifiedDate()
664+
{
665+
666+
$composerExtraStraussJson = <<<'EOD'
667+
{
668+
"extra":{
669+
"strauss": {
670+
"namespace_prefix": "BrianHenryIE\\Strauss\\",
671+
"include_modified_date": false
672+
}
673+
}
674+
}
675+
EOD;
676+
$tmpfname = tempnam(sys_get_temp_dir(), 'strauss-test-');
677+
file_put_contents($tmpfname, $composerExtraStraussJson);
678+
679+
$composer = Factory::create(new NullIO(), $tmpfname);
680+
681+
$sut = new StraussConfig($composer);
682+
683+
$this->assertFalse($sut->isIncludeModifiedDate());
684+
}
632685
}

tests/Unit/LicenserTest.php

Lines changed: 43 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,6 @@ public function testFindLicenceFilesPathsAreRelative()
7171
* @see https://www.phpliveregex.com/p/A5y
7272
*/
7373

74-
// https://schibsted.com/blog/mocking-the-file-system-using-phpunit-and-vfsstream/
75-
76-
7774
/**
7875
* @see https://github.com/AuthorizeNet/sdk-php/blob/a3e76f96f674d16e892f87c58bedb99dada4b067/lib/net/authorize/api/contract/v1/ANetApiRequestType.php
7976
*
@@ -106,6 +103,49 @@ public function testAppendHeaderCommentInformationNoHeader()
106103
* @see https://github.com/BrianHenryIE/strauss
107104
*/
108105
106+
namespace net\authorize\api\contract\v1;
107+
EOD;
108+
109+
$actual = $sut->addChangeDeclarationToPhpString($given, '25-April-2021', 'proprietary');
110+
111+
$this->assertEquals($expected, $actual);
112+
}
113+
114+
115+
// https://schibsted.com/blog/mocking-the-file-system-using-phpunit-and-vfsstream/
116+
117+
/**
118+
* Not including the date was reported as not working.
119+
*
120+
* @see https://github.com/BrianHenryIE/strauss/issues/35
121+
*
122+
* @covers ::addChangeDeclarationToPhpString
123+
*/
124+
public function testAppendHeaderCommentNoDate()
125+
{
126+
127+
$author = 'BrianHenryIE';
128+
129+
$config = $this->createMock(StraussConfig::class);
130+
$config->expects($this->once())->method('isIncludeModifiedDate')->willReturn(false);
131+
132+
$sut = new Licenser($config, __DIR__, array(), $author);
133+
134+
$given = <<<'EOD'
135+
<?php
136+
137+
namespace net\authorize\api\contract\v1;
138+
EOD;
139+
140+
$expected = <<<'EOD'
141+
<?php
142+
/**
143+
* @license proprietary
144+
*
145+
* Modified by BrianHenryIE using Strauss.
146+
* @see https://github.com/BrianHenryIE/strauss
147+
*/
148+
109149
namespace net\authorize\api\contract\v1;
110150
EOD;
111151

0 commit comments

Comments
 (0)