class Phpunit < Formula desc "Programmer-oriented testing framework for PHP" homepage "https://phpunit.de" url "https://phar.phpunit.de/phpunit-9.5.14.phar" sha256 "19f8d64750fade9f43a04f21ba9715cd87a5dafa47b98923be98f174596da53a" license "BSD-3-Clause" livecheck do url "https://phar.phpunit.de/" regex(/href=.*?phpunit[._-]v?(\d+(?:\.\d+)+)\.phar/i) end bottle do sha256 cellar: :any_skip_relocation, all: "adb810deb830df6672530acef55a4f7c95e9c530cb1f4d656b7c8841bfd5b872" end depends_on "php" => :test def install bin.install "phpunit-#{version}.phar" => "phpunit" end test do (testpath/"src/autoload.php").write <<~EOS '/Email.php' ); } $cn = strtolower($class); if (isset($classes[$cn])) { require __DIR__ . $classes[$cn]; } }, true, false ); EOS (testpath/"src/Email.php").write <<~EOS ensureIsValidEmail($email); $this->email = $email; } public static function fromString(string $email): self { return new self($email); } public function __toString(): string { return $this->email; } private function ensureIsValidEmail(string $email): void { if (!filter_var($email, FILTER_VALIDATE_EMAIL)) { throw new InvalidArgumentException( sprintf( '"%s" is not a valid email address', $email ) ); } } } EOS (testpath/"tests/EmailTest.php").write <<~EOS assertInstanceOf( Email::class, Email::fromString('user@example.com') ); } public function testCannotBeCreatedFromInvalidEmailAddress(): void { $this->expectException(InvalidArgumentException::class); Email::fromString('invalid'); } public function testCanBeUsedAsString(): void { $this->assertEquals( 'user@example.com', Email::fromString('user@example.com') ); } } EOS assert_match(/^OK \(3 tests, 3 assertions\)$/, shell_output("#{bin}/phpunit --bootstrap src/autoload.php tests/EmailTest.php")) end end