|
| 1 | +<?php |
| 2 | + |
| 3 | +/* |
| 4 | + * This file is part of the StyleCI SDK. |
| 5 | + * |
| 6 | + * (c) Alt Three Services Limited |
| 7 | + * |
| 8 | + * For the full copyright and license information, please view the LICENSE |
| 9 | + * file that was distributed with this source code. |
| 10 | + */ |
| 11 | + |
| 12 | +namespace StyleCI\Tests\SDK; |
| 13 | + |
| 14 | +use GrahamCampbell\TestBenchCore\MockeryTrait; |
| 15 | +use GuzzleHttp\ClientInterface; |
| 16 | +use Mockery; |
| 17 | +use PHPUnit_Framework_TestCase; |
| 18 | +use Psr\Http\Message\ResponseInterface; |
| 19 | +use StyleCI\SDK\Client; |
| 20 | + |
| 21 | +/** |
| 22 | + * This is the client test class. |
| 23 | + * |
| 24 | + * @author Graham Campbell <[email protected]> |
| 25 | + */ |
| 26 | +class ClientTest extends PHPUnit_Framework_TestCase |
| 27 | +{ |
| 28 | + use MockeryTrait; |
| 29 | + |
| 30 | + public function testCanBeInstantiated() |
| 31 | + { |
| 32 | + $this->assertInstanceOf(Client::class, new Client()); |
| 33 | + } |
| 34 | + |
| 35 | + public function testCanGetFixers() |
| 36 | + { |
| 37 | + $client = new Client($mock = Mockery::mock(ClientInterface::class)); |
| 38 | + |
| 39 | + $mock->shouldReceive('request')->once()->with('GET', 'fixers')->andReturn($response = Mockery::mock(ResponseInterface::class)); |
| 40 | + |
| 41 | + $response->shouldReceive('getBody')->once()->andReturn('[{"name":"align_double_arrow","description":"Align double arrow symbols in consecutive lines.","risky":false,"conflict":"unalign_double_arrow","aliases":[]}]'); |
| 42 | + |
| 43 | + $this->assertSame([['name' => 'align_double_arrow', 'description' => 'Align double arrow symbols in consecutive lines.', 'risky' => false, 'conflict' => 'unalign_double_arrow', 'aliases' => []]], $client->fixers()); |
| 44 | + } |
| 45 | + |
| 46 | + public function testCanGetPresets() |
| 47 | + { |
| 48 | + $client = new Client($mock = Mockery::mock(ClientInterface::class)); |
| 49 | + |
| 50 | + $mock->shouldReceive('request')->once()->with('GET', 'presets')->andReturn($response = Mockery::mock(ResponseInterface::class)); |
| 51 | + |
| 52 | + $response->shouldReceive('getBody')->once()->andReturn('[{"title":"PSR1","name":"psr1","fixers":["encoding","full_opening_tag","psr4"]}]'); |
| 53 | + |
| 54 | + $this->assertSame([['title' => 'PSR1', 'name' => 'psr1', 'fixers' => ['encoding', 'full_opening_tag', 'psr4']]], $client->presets()); |
| 55 | + } |
| 56 | +} |
0 commit comments