Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions tests/MockServiceProviderTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

declare(strict_types=1);

namespace Yiisoft\Yii\Testing\Tests;

use PHPUnit\Framework\TestCase;
use Yiisoft\Yii\Testing\MockServiceProvider;

class MockServiceProviderTest extends TestCase
{
public function testGetDefinitionsWillReturnDefinitionsSetInArray(): void
{
$mockServiceProvider = new MockServiceProvider();
$mockServiceProvider->setDefinition('example-id-001', ['class' => 'Example1\Class1\Position1']);
$mockServiceProvider->setDefinition('example-id-002', 'Example1\Class2\Position2');
$mockServiceProvider->setDefinition('example-id-003', 'Example3\Class3\Position3');

$this->assertEquals([
'example-id-001' => ['class' => 'Example1\Class1\Position1'],
'example-id-002' => 'Example1\Class2\Position2',
'example-id-003' => 'Example3\Class3\Position3',
], $mockServiceProvider->getDefinitions());
}

public function testGetExtensionsWillReturnEmptyArray(): void
{
$this->assertEmpty((new MockServiceProvider())->getExtensions());
}
Comment on lines +12 to +29
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These tests do not correspond to real usage of the provider. Would you please make it closer to real usage?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you provide a link where I can find real usages? I'll check it and modify both tests

}
42 changes: 42 additions & 0 deletions tests/ResponseGrabberTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php

declare(strict_types=1);

namespace Yiisoft\Yii\Testing\Tests;

use Nyholm\Psr7\Response;
use PHPUnit\Framework\TestCase;
use RuntimeException;
use Yiisoft\Yii\Testing\ResponseAccessor;
use Yiisoft\Yii\Testing\ResponseGrabber;

class ResponseGrabberTest extends TestCase
{
public function testGetResponseWillReturnResponseAccessorSetResponse(): void
{
$response = new Response(200, body: '{"key": "value"}', reason: 'Ok with body', version: '1.1');

$responseGrabber = new ResponseGrabber();
$responseGrabber->setResponse($response);

$this->assertEquals(new ResponseAccessor($response), $responseGrabber->getResponse());
}

public function testGetResponseWillThrowExceptionIfSetResponseIsCalledWithNullParameter(): void
{
$this->expectException(RuntimeException::class);
$this->expectExceptionMessage('Response is null');

$responseGrabber = new ResponseGrabber();
$responseGrabber->setResponse(null);
$responseGrabber->getResponse();
}

public function testGetResponseWillThrowExceptionIfResponseIsNotSet(): void
{
$this->expectException(RuntimeException::class);
$this->expectExceptionMessage('Response is null');

(new ResponseGrabber())->getResponse();
}
Comment on lines +15 to +41
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These tests do not correspond to real usage. Would you please make it closer to real usage?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you provide a link where I can find real usages? I'll check it and modify both tests

}
Loading