Skip to content

Instantly share code, notes, and snippets.

@ismail1432
Created December 20, 2021 22:27
Show Gist options
  • Save ismail1432/44ba627f8c58b22bfed0b994e86727a6 to your computer and use it in GitHub Desktop.
Save ismail1432/44ba627f8c58b22bfed0b994e86727a6 to your computer and use it in GitHub Desktop.
<?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