Skip to content

Commit d0862cc

Browse files
committed
phpunit@11 (new formula)
1 parent 6bcf771 commit d0862cc

File tree

1 file changed

+115
-0
lines changed

1 file changed

+115
-0
lines changed

Formula/[email protected]

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
class PhpunitAT11 < Formula
2+
desc "Programmer-oriented testing framework for PHP"
3+
homepage "https://phpunit.de"
4+
url "https://phar.phpunit.de/phpunit-11.5.28.phar"
5+
sha256 "339427750d392ac00125d0938b503614b964c4a6109ad8f143267c91217d8719"
6+
license "BSD-3-Clause"
7+
8+
livecheck do
9+
url "https://phar.phpunit.de/"
10+
regex(%r{/phpunit[._-]v?(11\.\d+(?:\.\d+)+)\.phar}i)
11+
end
12+
13+
depends_on "php" => :test
14+
15+
def install
16+
bin.install "phpunit-#{version}.phar" => "phpunit-#{version.major}"
17+
end
18+
19+
test do
20+
(testpath/"src/autoload.php").write <<~PHP
21+
<?php
22+
spl_autoload_register(
23+
function($class) {
24+
static $classes = null;
25+
if ($classes === null) {
26+
$classes = array(
27+
'email' => '/Email.php'
28+
);
29+
}
30+
$cn = strtolower($class);
31+
if (isset($classes[$cn])) {
32+
require __DIR__ . $classes[$cn];
33+
}
34+
},
35+
true,
36+
false
37+
);
38+
PHP
39+
40+
(testpath/"src/Email.php").write <<~PHP
41+
<?php
42+
declare(strict_types=1);
43+
44+
final class Email
45+
{
46+
private $email;
47+
48+
private function __construct(string $email)
49+
{
50+
$this->ensureIsValidEmail($email);
51+
52+
$this->email = $email;
53+
}
54+
55+
public static function fromString(string $email): self
56+
{
57+
return new self($email);
58+
}
59+
60+
public function __toString(): string
61+
{
62+
return $this->email;
63+
}
64+
65+
private function ensureIsValidEmail(string $email): void
66+
{
67+
if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
68+
throw new InvalidArgumentException(
69+
sprintf(
70+
'"%s" is not a valid email address',
71+
$email
72+
)
73+
);
74+
}
75+
}
76+
}
77+
PHP
78+
79+
(testpath/"tests/EmailTest.php").write <<~PHP
80+
<?php
81+
declare(strict_types=1);
82+
83+
use PHPUnit\\Framework\\TestCase;
84+
85+
final class EmailTest extends TestCase
86+
{
87+
public function testCanBeCreatedFromValidEmailAddress(): void
88+
{
89+
$this->assertInstanceOf(
90+
Email::class,
91+
Email::fromString('[email protected]')
92+
);
93+
}
94+
95+
public function testCannotBeCreatedFromInvalidEmailAddress(): void
96+
{
97+
$this->expectException(InvalidArgumentException::class);
98+
99+
Email::fromString('invalid');
100+
}
101+
102+
public function testCanBeUsedAsString(): void
103+
{
104+
$this->assertEquals(
105+
106+
Email::fromString('[email protected]')
107+
);
108+
}
109+
}
110+
111+
PHP
112+
assert_match(/^OK \(3 tests, 3 assertions\)$/,
113+
shell_output("#{bin}/phpunit --bootstrap src/autoload.php tests/EmailTest.php"))
114+
end
115+
end

0 commit comments

Comments
 (0)