|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace Tests\Unit\Lexicons\App\Bsky\Feed; |
| 4 | + |
| 5 | +use Atproto\Client; |
| 6 | +use Atproto\Exceptions\InvalidArgumentException; |
| 7 | +use Atproto\Lexicons\App\Bsky\Feed\GetTimeline; |
| 8 | +use PHPUnit\Framework\TestCase; |
| 9 | + |
| 10 | +class GetTimelineTest extends TestCase |
| 11 | +{ |
| 12 | + private static GetTimeline $instance; |
| 13 | + |
| 14 | + public static function setUpBeforeClass(): void |
| 15 | + { |
| 16 | + static::$instance = (new Client())->app()->bsky()->feed()->getTimeline()->forge(); |
| 17 | + |
| 18 | + } |
| 19 | + |
| 20 | + public function testLimitCanChangeTheLimit(): void |
| 21 | + { |
| 22 | + $getTimeline = static::$instance; |
| 23 | + |
| 24 | + $this->assertSame(50, $getTimeline->limit()); // default value |
| 25 | + |
| 26 | + $getTimeline->limit($expected = 10); |
| 27 | + $actual = $getTimeline->limit(); |
| 28 | + |
| 29 | + $this->assertSame($expected, $actual); |
| 30 | + } |
| 31 | + |
| 32 | + /** @dataProvider provideInvalidLimitCases */ |
| 33 | + public function testLimitThrowsExceptionWhenPassedInvalidArgument(int $invalidLimit): void |
| 34 | + { |
| 35 | + $this->expectException(InvalidArgumentException::class); |
| 36 | + $this->expectExceptionMessage("The limit must be between or equal to 1 and 100."); |
| 37 | + |
| 38 | + static::$instance->limit($invalidLimit); |
| 39 | + } |
| 40 | + |
| 41 | + public static function provideInvalidLimitCases(): array |
| 42 | + { |
| 43 | + return [ |
| 44 | + [0], |
| 45 | + [-1], |
| 46 | + [101], |
| 47 | + [102] |
| 48 | + ]; |
| 49 | + } |
| 50 | + |
| 51 | + public function testCursorCanChangeTheCursor(): void |
| 52 | + { |
| 53 | + $this->assertNull(static::$instance->cursor()); // it is not available by default |
| 54 | + |
| 55 | + static::$instance->cursor($expected = 'cursor value'); |
| 56 | + $actual = static::$instance->cursor(); |
| 57 | + |
| 58 | + $this->assertSame($expected, $actual); |
| 59 | + } |
| 60 | + |
| 61 | + public function testAlgorithmCanChangeTheAlgorithm(): void |
| 62 | + { |
| 63 | + $this->assertNull(static::$instance->algorithm()); |
| 64 | + |
| 65 | + static::$instance->algorithm($expected = 'algorithm value'); |
| 66 | + $actual = static::$instance->algorithm(); |
| 67 | + |
| 68 | + $this->assertSame($expected, $actual); |
| 69 | + } |
| 70 | +} |
0 commit comments