-
Notifications
You must be signed in to change notification settings - Fork 147
[TASK] Add trait providing standard implementation of Commentable
#1206
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 2 commits
fa0e11c
de45497
94a17b4
65bb1e7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace Sabberworm\CSS\Comment; | ||
|
|
||
| /** | ||
| * Provides a standard reusable implementation of `Commentable`. | ||
| * | ||
| * @internal | ||
| * | ||
| * @phpstan-require-implements Commentable | ||
| */ | ||
| trait CommentContainer | ||
oliverklee marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| { | ||
| /** | ||
| * @var list<Comment> | ||
| */ | ||
| protected $comments = []; | ||
|
|
||
| /** | ||
| * @param list<Comment> $comments | ||
| */ | ||
| public function addComments(array $comments): void | ||
| { | ||
| $this->comments = \array_merge($this->comments, $comments); | ||
| } | ||
|
|
||
| /** | ||
| * @return list<Comment> | ||
| */ | ||
| public function getComments(): array | ||
| { | ||
| return $this->comments; | ||
| } | ||
|
|
||
| /** | ||
| * @param list<Comment> $comments | ||
| */ | ||
| public function setComments(array $comments): void | ||
| { | ||
| $this->comments = $comments; | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,239 @@ | ||||||
| <?php | ||||||
|
|
||||||
| declare(strict_types=1); | ||||||
|
|
||||||
| namespace Sabberworm\CSS\Tests\Unit\Comment; | ||||||
|
|
||||||
| use PHPUnit\Framework\Constraint\LogicalAnd; | ||||||
| use PHPUnit\Framework\Constraint\TraversableContains; | ||||||
| use PHPUnit\Framework\TestCase; | ||||||
| use Sabberworm\CSS\Comment\Comment; | ||||||
| use Sabberworm\CSS\Comment\Commentable; | ||||||
| use Sabberworm\CSS\Tests\Unit\Comment\Fixtures\ConcreteCommentContainer; | ||||||
| use TRegx\DataProvider\DataProviders; | ||||||
|
|
||||||
| /** | ||||||
| * @covers \Sabberworm\CSS\Comment\CommentContainer | ||||||
| */ | ||||||
| final class CommentContainerTest extends TestCase | ||||||
| { | ||||||
| /** | ||||||
| * @var Commentable | ||||||
JakeQZ marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||||
| */ | ||||||
| private $subject; | ||||||
|
|
||||||
| protected function setUp(): void | ||||||
| { | ||||||
| $this->subject = new ConcreteCommentContainer(); | ||||||
| } | ||||||
|
|
||||||
| /** | ||||||
| * @test | ||||||
| */ | ||||||
| public function getCommentsInitiallyReturnsEmptyArray(): void | ||||||
| { | ||||||
| self::assertSame([], $this->subject->getComments()); | ||||||
| } | ||||||
|
|
||||||
| /** | ||||||
| * @return array<non-empty-string, array{0: list<Comment>}> | ||||||
| */ | ||||||
| public function provideCommentArray(): array | ||||||
| { | ||||||
| return [ | ||||||
| 'no comment' => [[]], | ||||||
| 'one comment' => [[new Comment('Is this really a spoon?')]], | ||||||
| 'two comments' => [[ | ||||||
| new Comment('I’m a teapot.'), | ||||||
| new Comment('I’m a cafetière.'), | ||||||
JakeQZ marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
| ]], | ||||||
| ]; | ||||||
| } | ||||||
|
|
||||||
| /** | ||||||
| * @test | ||||||
| * | ||||||
| * @param list<Comment> $comments | ||||||
| * | ||||||
| * @dataProvider provideCommentArray | ||||||
| */ | ||||||
| public function getCommentsAfterCommentsAddedToVirginContainerReturnsThoseComments(array $comments): void | ||||||
| { | ||||||
| $this->subject->addComments($comments); | ||||||
|
|
||||||
| self::assertSame($comments, $this->subject->getComments()); | ||||||
| } | ||||||
|
|
||||||
| /** | ||||||
| * @test | ||||||
| * | ||||||
| * @param list<Comment> $comments | ||||||
| * | ||||||
| * @dataProvider provideCommentArray | ||||||
| */ | ||||||
| public function getCommentsAfterEmptyArrayOfCommentsAddedReturnsOriginalComments(array $comments): void | ||||||
|
||||||
| public function getCommentsAfterEmptyArrayOfCommentsAddedReturnsOriginalComments(array $comments): void | |
| public function setCommentsWithEmptyArrayKeepsOriginalCommentsUnchanged(array $comments): void |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Apart from getCommentsInitiallyReturnsEmptyArray(), all the test methods focus on either addComments() (first group) or setComments() (last group). So perhaps they all be renamed like addCommentsDoesXYZ() and setCommentsDoesXYZ - WDYT?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I'd like that!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
oliverklee marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace Sabberworm\CSS\Tests\Unit\Comment\Fixtures; | ||
|
|
||
| use Sabberworm\CSS\Comment\Commentable; | ||
| use Sabberworm\CSS\Comment\CommentContainer; | ||
|
|
||
| final class ConcreteCommentContainer implements Commentable | ||
| { | ||
| use CommentContainer; | ||
| } |
Uh oh!
There was an error while loading. Please reload this page.