Created
December 20, 2021 22:27
-
-
Save ismail1432/44ba627f8c58b22bfed0b994e86727a6 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Article.php | |
final class Article | |
{ | |
// properties, getters | |
public function markAsPublished(): self | |
{ | |
if ($this->status === Article::DELETED)) { | |
throw new LogicException(sprintf("Cannot mark as published as the article is deleted")); | |
} | |
} | |
$this->status = Article::PUBLISHED; | |
return $this; | |
} | |
} | |
// ArticleTest.php | |
use PHPUnit\Framework\TestCase; | |
final class ArticleTest extends TestCase | |
{ | |
public function testItMarksAsPublished(): void | |
{ | |
$article = (new Article)->markAsPublished(); | |
// ✨ If the constant value change this test will fail | |
self::assertEquals('published', $article->getStatus()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment