|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace spec\AlexisLefebvre\Bundle\AsyncTweetsBundle\Entity; |
| 4 | + |
| 5 | +use AlexisLefebvre\Bundle\AsyncTweetsBundle\Entity\Tweet; |
| 6 | +use PhpSpec\Exception\Example\SkippingException; |
| 7 | +use PhpSpec\ObjectBehavior; |
| 8 | + |
| 9 | +class TweetSpec extends ObjectBehavior |
| 10 | +{ |
| 11 | + public function let(Tweet $tweet) |
| 12 | + { |
| 13 | + $this->beConstructedWith($tweet); |
| 14 | + |
| 15 | + $fakeTweet = new \stdClass(); |
| 16 | + $fakeTweet->created_at = 'now'; |
| 17 | + $fakeTweet->text = 'Hello Twitter! #myfirstTweet'; |
| 18 | + $fakeTweet->retweet_count = 5; |
| 19 | + $fakeTweet->favorite_count = 12; |
| 20 | + |
| 21 | + $this->setValues($fakeTweet); |
| 22 | + } |
| 23 | + |
| 24 | + public function it_is_initializable() |
| 25 | + { |
| 26 | + $this->shouldHaveType(Tweet::class); |
| 27 | + } |
| 28 | + |
| 29 | + public function it_should_have_a_created_at_datetime() |
| 30 | + { |
| 31 | + $this->getCreatedAt()->shouldHaveType(new \DateTime()); |
| 32 | + } |
| 33 | + |
| 34 | + public function it_should_have_the_title() |
| 35 | + { |
| 36 | + $this->getText()->shouldBeEqualTo('Hello Twitter! #myfirstTweet'); |
| 37 | + } |
| 38 | + |
| 39 | + public function it_should_have_retweet_count() |
| 40 | + { |
| 41 | + $this->getRetweetCount()->shouldBeEqualTo(5); |
| 42 | + } |
| 43 | + |
| 44 | + public function it_should_have_favorite_count() |
| 45 | + { |
| 46 | + $this->getFavoriteCount()->shouldBeEqualTo(12); |
| 47 | + } |
| 48 | + |
| 49 | + public function it_should_not_be_in_timeline() |
| 50 | + { |
| 51 | + $this->shouldNotBeInTimeline(); |
| 52 | + } |
| 53 | + |
| 54 | + public function it_should_not_allow_invalid_medias() |
| 55 | + { |
| 56 | + /* @see https://github.com/phpspec/phpspec/issues/119#issuecomment-43436579 */ |
| 57 | + if (version_compare(PHP_VERSION, '7', '<')) { |
| 58 | + throw new SkippingException('Unsupported type hinting with PHP < 7'); |
| 59 | + } |
| 60 | + |
| 61 | + $this->shouldThrow('\TypeError')->during('addMedia', [null]); |
| 62 | + $this->shouldThrow('\TypeError')->during('removeMedia', [null]); |
| 63 | + } |
| 64 | +} |
0 commit comments