mirror of
https://github.com/friendica/friendica
synced 2025-05-01 08:24:23 +02:00
Introduce DiceTestTrait for partial mocking DI:: calls
This commit is contained in:
parent
10e6089405
commit
c7f54d83ce
3 changed files with 130 additions and 91 deletions
|
@ -2,12 +2,70 @@
|
|||
|
||||
namespace Friendica\Test\src\Util;
|
||||
|
||||
use Friendica\Test\DiceTestTrait;
|
||||
use Friendica\Test\MockedTest;
|
||||
use Friendica\Util\Images;
|
||||
use GuzzleHttp\Handler\MockHandler;
|
||||
use GuzzleHttp\Psr7\Response;
|
||||
|
||||
class ImagesTest extends MockedTest
|
||||
{
|
||||
public function testGetInfoFromURL()
|
||||
{
|
||||
use DiceTestTrait;
|
||||
|
||||
public static function setUpBeforeClass(): void
|
||||
{
|
||||
parent::setUpBeforeClass();
|
||||
|
||||
self::setUpDice();
|
||||
}
|
||||
|
||||
public function dataImages()
|
||||
{
|
||||
return [
|
||||
'image' => [
|
||||
'url' => 'https://pbs.twimg.com/profile_images/2365515285/9re7kx4xmc0eu9ppmado.png',
|
||||
'headers' => [
|
||||
'Server' => 'tsa_b',
|
||||
'Content-Type' => 'image/png',
|
||||
'Cache-Control' => 'max-age=604800,must-revalidate',
|
||||
'Last-Modified' => 'Thu,04Nov201001:42:54GMT',
|
||||
'Content-Length' => '24875',
|
||||
'Access-Control-Allow-Origin' => '*',
|
||||
'Access-Control-Expose-Headers' => 'Content-Length',
|
||||
'Date' => 'Mon,23Aug202112:39:00GMT',
|
||||
'Connection' => 'keep-alive',
|
||||
],
|
||||
'data' => file_get_contents(__DIR__ . '/../../datasets/curl/image.content'),
|
||||
'assertion' => [
|
||||
'0' => '400',
|
||||
'1' => '400',
|
||||
'2' => '3',
|
||||
'3' => 'width="400" height="400"',
|
||||
'bits' => '8',
|
||||
'mime' => 'image/png',
|
||||
'size' => '24875',
|
||||
]
|
||||
],
|
||||
'emptyUrl' => [
|
||||
'url' => '',
|
||||
'headers' => [],
|
||||
'data' => '',
|
||||
'assertion' => [],
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the Images::getInfoFromURL() method
|
||||
*
|
||||
* @dataProvider dataImages
|
||||
*/
|
||||
public function testGetInfoFromURL(string $url, array $headers, string $data, array $assertion)
|
||||
{
|
||||
self::$httpRequestHandler->setHandler(new MockHandler([
|
||||
new Response(200, $headers, $data),
|
||||
]));
|
||||
|
||||
self::assertArraySubset($assertion, Images::getInfoFromURL($url));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue