Skip to content

Commit

Permalink
attempt to soothe windows
Browse files Browse the repository at this point in the history
  • Loading branch information
pmjones committed Sep 27, 2023
1 parent b77fd41 commit dd27400
Show file tree
Hide file tree
Showing 10 changed files with 51 additions and 25 deletions.
14 changes: 14 additions & 0 deletions tests/Assertions.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php
declare(strict_types=1);

namespace Qiq;

trait Assertions
{
public function assertSameString(string $expect, string $actual) : void
{
$expect = str_replace("\r\n", "\n", $expect);
$actual = str_replace("\r\n", "\n", $actual);
$this->assertSame($expect, $actual);
}
}
6 changes: 3 additions & 3 deletions tests/Helper/Html/CheckboxFieldsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public function test() : void
<label><input type="checkbox" name="foo[]" value="maybe" />May &amp; be</label>

HTML;
$this->assertSame($expect, $actual);
$this->assertSameString($expect, $actual);
}

public function testSingleOption() : void
Expand All @@ -36,7 +36,7 @@ public function testSingleOption() : void
<label><input type="checkbox" name="foo" value="1" checked />Yes</label>

HTML;
$this->assertSame($expect, $actual);
$this->assertSameString($expect, $actual);
}

public function testScalarChecked() : void
Expand All @@ -53,6 +53,6 @@ public function testScalarChecked() : void
<label><input type="checkbox" name="foo[]" value="maybe" />May &amp; be</label>

HTML;
$this->assertSame($expect, $actual);
$this->assertSameString($expect, $actual);
}
}
4 changes: 2 additions & 2 deletions tests/Helper/Html/DlTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ public function test() : void
<dd>Baz Def</dd>
</dl>
HTML;
$this->assertSame($expect, $actual);
$this->assertSameString($expect, $actual);
$actual = $this->helpers->dl([]);
$expect = '';
$this->assertSame($expect, $actual);
$this->assertSameString($expect, $actual);
}
}
3 changes: 3 additions & 0 deletions tests/Helper/Html/HtmlHelperTestCase.php
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
<?php
namespace Qiq\Helper\Html;

use Qiq\Assertions;
use Qiq\Container;
use Qiq\Indent;

abstract class HtmlHelperTestCase extends \PHPUnit\Framework\TestCase
{
use Assertions;

protected HtmlHelpers $helpers;

protected Container $container;
Expand Down
2 changes: 1 addition & 1 deletion tests/Helper/Html/ItemsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ public function test() : void
<li>&gt;dib</li>

HTML;
$this->assertSame($expect, $actual);
$this->assertSameString($expect, $actual);
}
}
4 changes: 2 additions & 2 deletions tests/Helper/Html/OlTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ public function test() : void
<li>&gt;dib</li>
</ol>
HTML;
$this->assertSame($expect, $actual);
$this->assertSameString($expect, $actual);
$actual = $this->helpers->ol([]);
$expect = '';
$this->assertSame($expect, $actual);
$this->assertSameString($expect, $actual);
}
}
2 changes: 1 addition & 1 deletion tests/Helper/Html/RadioFieldsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@ public function test() : void
<label><input type="radio" name="foo" value="maybe" />May &amp; be</label>

HTML;
$this->assertSame($expect, $actual);
$this->assertSameString($expect, $actual);
}
}
4 changes: 2 additions & 2 deletions tests/Helper/Html/SelectTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public function test() : void
</optgroup>
</select>
HTML;
$this->assertSame($expect, $actual);
$this->assertSameString($expect, $actual);
}

public function testMultiple() : void
Expand Down Expand Up @@ -87,6 +87,6 @@ public function testMultiple() : void
</optgroup>
</select>
HTML;
$this->assertSame($expect, $actual);
$this->assertSameString($expect, $actual);
}
}
4 changes: 2 additions & 2 deletions tests/Helper/Html/UlTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ public function test() : void
<li>&gt;dib</li>
</ul>
HTML;
$this->assertSame($expect, $actual);
$this->assertSameString($expect, $actual);
$actual = $this->helpers->ul([]);
$expect = '';
$this->assertSame($expect, $actual);
$this->assertSameString($expect, $actual);
}
}
33 changes: 21 additions & 12 deletions tests/TemplateTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,15 @@

namespace Qiq;

use Qiq\Assertions;
use Qiq\Compiler\NonCompiler;
use Qiq\Compiler\QiqCompiler;
use RuntimeException;

class TemplateTest extends \PHPUnit\Framework\TestCase
{
use Assertions;

protected HtmlTemplate $template;

protected function setUp() : void
Expand Down Expand Up @@ -94,14 +97,22 @@ public function testRelative() : void
public function testRelativeFailure() : void
{
$this->template->setView('rel/foo/broken');
$this->expectException(Exception\FileNotFound::class);
$this->expectExceptionMessage(<<<EOT
Could not resolve dots in template name.
Original name: '../../../zim'
Resolved into: '../zim'
Probably too many '../' in the original name.
EOT);
($this->template)();

try {
($this->template)();
} catch (Exception\FileNotFound $e) {
$expect = <<<'EXPECT'
Could not resolve dots in template name.
Original name: '../../../zim'
Resolved into: '../zim'
Probably too many '../' in the original name.
EXPECT;
$actual = $e->getMessage();
$this->assertSameString(trim($expect), trim($actual));
return;
}

throw new RuntimeException('Should have thrown exception');
}

public function testExtends() : void
Expand All @@ -111,19 +122,17 @@ public function testExtends() : void
$expect = <<<EOT
Layout 1 Content
View 1 Content
Foo 3a View
Foo 1 Layout
Foo 2 Layout
Foo 3 Layout
Foo 1 View
Foo 2 View
Foo 3b View
EOT;
$actual = ($this->template)();
$this->assertSame($expect, $actual);
$actual = str_replace("\n\n", "\n", $actual);
$this->assertSameString(trim($expect), trim($actual));
}

public function testInheritanceDocExample() : void
Expand Down

0 comments on commit dd27400

Please sign in to comment.