Skip to content

Commit 06cb824

Browse files
committed
Rename test double classes
1 parent 4cbdf89 commit 06cb824

15 files changed

+75
-75
lines changed

README.md

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -290,15 +290,15 @@ or extend the `Tarantool\PhpUnit\TestCase` class.
290290

291291
The library provides several helper classes to create test doubles for the [Tarantool Сlient](https://github.com/tarantool-php/client)
292292
to avoid sending real requests to the Tarantool server. For the convenience of creating such objects,
293-
add the trait `ClientMocking` to your test class:
293+
add the trait `TestDoubleClient` to your test class:
294294

295295
```php
296296
use PHPUnit\Framework\TestCase;
297-
use Tarantool\PhpUnit\Client\ClientMocking;
297+
use Tarantool\PhpUnit\Client\TestDoubleClient;
298298

299299
final class MyTest extends TestCase
300300
{
301-
use ClientMocking;
301+
use TestDoubleClient;
302302

303303
// ...
304304
}
@@ -314,15 +314,15 @@ A dummy client object can be created as follows:
314314
```php
315315
public function testFoo() : void
316316
{
317-
$dummyClient = $this->createMockClient();
317+
$dummyClient = $this->createDummyClient();
318318

319319
// ...
320320
}
321321
```
322322

323323
To simulate specific scenarios, such as establishing a connection to a server
324324
or returning specific responses in a specific order from the server, use the facilities
325-
of the `MockClientBuilder` class. For example, to simulate the `PING` request:
325+
of the `TestDoubleClientBuilder` class. For example, to simulate the `PING` request:
326326

327327
```php
328328
use Tarantool\Client\Request\PingRequest;
@@ -332,7 +332,7 @@ final class MyTest extends TestCase
332332
{
333333
public function testFoo() : void
334334
{
335-
$mockClient = $this->getMockClientBuilder()
335+
$mockClient = $this->getTestDoubleClientBuilder()
336336
->shouldSend(new PingRequest())
337337
->build();
338338

@@ -347,20 +347,20 @@ Another example, sending two `EVALUATE` requests and returning a different respo
347347

348348
```php
349349
use Tarantool\Client\RequestTypes;
350-
use Tarantool\PhpUnit\Client\DummyFactory;
350+
use Tarantool\PhpUnit\Client\TestDoubleFactory;
351351
use Tarantool\PhpUnit\TestCase;
352352

353353
final class MyTest extends TestCase
354354
{
355355
public function testFoo() : void
356356
{
357-
$mockClient = $this->getMockClientBuilder()
357+
$mockClient = $this->getTestDoubleClientBuilder()
358358
->shouldSend(
359359
RequestTypes::EVALUATE,
360360
RequestTypes::EVALUATE
361361
)->willReceive(
362-
DummyFactory::createResponseFromData([2]),
363-
DummyFactory::createResponseFromData([3])
362+
TestDoubleFactory::createResponseFromData([2]),
363+
TestDoubleFactory::createResponseFromData([3])
364364
)->build();
365365

366366
// ...
@@ -372,11 +372,11 @@ final class MyTest extends TestCase
372372
The above example can be simplified to:
373373

374374
```php
375-
$mockClient = $this->getMockClientBuilder()
375+
$mockClient = $this->getTestDoubleClientBuilder()
376376
->shouldHandle(
377377
RequestTypes::EVALUATE,
378-
DummyFactory::createResponseFromData([2]),
379-
DummyFactory::createResponseFromData([3])
378+
TestDoubleFactory::createResponseFromData([2]),
379+
TestDoubleFactory::createResponseFromData([3])
380380
)->build();
381381
```
382382

phpunit-extension.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
</filter>
2727

2828
<extensions>
29-
<extension class="Tarantool\PhpUnit\Tests\Annotation\MockAnnotationExtension">
29+
<extension class="Tarantool\PhpUnit\Tests\Annotation\AnnotationExtension">
3030
<arguments>
3131
<array>
3232
<element key="bool">

src/Client/ClientMocking.php renamed to src/Client/TestDoubleClient.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,15 @@
1515

1616
use Tarantool\Client\Client;
1717

18-
trait ClientMocking
18+
trait TestDoubleClient
1919
{
20-
protected function getMockClientBuilder() : MockClientBuilder
20+
protected function getTestDoubleClientBuilder() : TestDoubleClientBuilder
2121
{
22-
return new MockClientBuilder($this);
22+
return new TestDoubleClientBuilder($this);
2323
}
2424

25-
protected function createMockClient() : Client
25+
protected function createDummyClient() : Client
2626
{
27-
return $this->getMockClientBuilder()->build();
27+
return $this->getTestDoubleClientBuilder()->build();
2828
}
2929
}

src/Client/MockClientBuilder.php renamed to src/Client/TestDoubleClientBuilder.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
use Tarantool\Client\Request\Request;
2424
use Tarantool\Client\Response;
2525

26-
final class MockClientBuilder
26+
final class TestDoubleClientBuilder
2727
{
2828
/** @var TestCase */
2929
private $testCase;
@@ -46,10 +46,10 @@ final class MockClientBuilder
4646
public function __construct(TestCase $testCase)
4747
{
4848
$this->testCase = $testCase;
49-
$this->responses = [DummyFactory::createEmptyResponse()];
49+
$this->responses = [TestDoubleFactory::createEmptyResponse()];
5050
}
5151

52-
public static function buildDefault() : Client
52+
public static function buildDummy() : Client
5353
{
5454
/** @psalm-suppress PropertyNotSetInConstructor */
5555
$self = new self(new class() extends TestCase {

src/Client/DummyFactory.php renamed to src/Client/TestDoubleFactory.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
use Tarantool\Client\Keys;
1717
use Tarantool\Client\Response;
1818

19-
final class DummyFactory
19+
final class TestDoubleFactory
2020
{
2121
public static function createResponse(array $body, array $header = []) : Response
2222
{

src/TestCase.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,12 @@
1515

1616
use PHPUnitExtras\TestCase as BaseTestCase;
1717
use Tarantool\PhpUnit\Annotation\Annotations;
18-
use Tarantool\PhpUnit\Client\ClientMocking;
18+
use Tarantool\PhpUnit\Client\TestDoubleClient;
1919
use Tarantool\PhpUnit\Expectation\Expectations;
2020

2121
abstract class TestCase extends BaseTestCase
2222
{
23-
use ClientMocking;
23+
use TestDoubleClient;
2424
use Annotations;
2525
use Expectations;
2626
}

tests/Annotation/MockAnnotationExtension.php renamed to tests/Annotation/AnnotationExtension.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,17 @@
1414
namespace Tarantool\PhpUnit\Tests\Annotation;
1515

1616
use Tarantool\Client\Client;
17-
use Tarantool\PhpUnit\Annotation\AnnotationExtension;
18-
use Tarantool\PhpUnit\Client\MockClientBuilder;
17+
use Tarantool\PhpUnit\Annotation\AnnotationExtension as BaseAnnotationExtension;
18+
use Tarantool\PhpUnit\Client\TestDoubleClientBuilder;
1919

20-
final class MockAnnotationExtension extends AnnotationExtension
20+
final class AnnotationExtension extends BaseAnnotationExtension
2121
{
2222
public $resolvedDnsOrOptions;
2323

2424
protected function getClient() : Client
2525
{
2626
$this->resolvedDnsOrOptions = $this->getClientConfig();
2727

28-
return MockClientBuilder::buildDefault();
28+
return TestDoubleClientBuilder::buildDummy();
2929
}
3030
}

tests/Annotation/AnnotationExtensionTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ final class AnnotationExtensionTest extends TestCase
2222
*/
2323
public function testConstructorUsesDefaultDsn() : void
2424
{
25-
$ext = new MockAnnotationExtension();
25+
$ext = new AnnotationExtension();
2626

2727
$ext->executeBeforeTest(__METHOD__);
2828
self::assertSame('tcp://127.0.0.1:3301', $ext->resolvedDnsOrOptions);
@@ -34,7 +34,7 @@ public function testConstructorUsesDefaultDsn() : void
3434
public function testConstructorUsesCustomDsn() : void
3535
{
3636
$dsn = 'tcp://tnt_foobar:3302';
37-
$ext = new MockAnnotationExtension($dsn);
37+
$ext = new AnnotationExtension($dsn);
3838

3939
$ext->executeBeforeTest(__METHOD__);
4040
self::assertSame($dsn, $ext->resolvedDnsOrOptions);
@@ -51,7 +51,7 @@ public function testGetClientConfigNormalizesDsnString() : void
5151
$envPortName = 'tnt_phpunit_env_port_'.random_int(1, 1000);
5252
putenv("$envHostName=$hostname");
5353
putenv("$envPortName=$port");
54-
$ext = new MockAnnotationExtension("tcp://%env($envHostName)%:%env($envPortName)%");
54+
$ext = new AnnotationExtension("tcp://%env($envHostName)%:%env($envPortName)%");
5555

5656
$ext->executeBeforeTest(__METHOD__);
5757
self::assertSame("tcp://$hostname:$port", $ext->resolvedDnsOrOptions);
@@ -68,7 +68,7 @@ public function testGetClientConfigNormalizesOptionArray() : void
6868
$envPortName = 'tnt_phpunit_env_port_'.random_int(1, 1000);
6969
putenv("$envHostName=$hostname");
7070
putenv("$envPortName=$port");
71-
$ext = new MockAnnotationExtension([
71+
$ext = new AnnotationExtension([
7272
'uri' => "tcp://%env($envHostName)%:%env($envPortName)%",
7373
'socket_timeout' => 10,
7474
'persistent' => true,

tests/Annotation/Processor/LuaProcessorTest.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,21 +16,21 @@
1616
use PHPUnit\Framework\TestCase;
1717
use Tarantool\Client\Request\EvaluateRequest;
1818
use Tarantool\PhpUnit\Annotation\Processor\LuaProcessor;
19-
use Tarantool\PhpUnit\Client\ClientMocking;
20-
use Tarantool\PhpUnit\Client\DummyFactory;
19+
use Tarantool\PhpUnit\Client\TestDoubleClient;
20+
use Tarantool\PhpUnit\Client\TestDoubleFactory;
2121

2222
final class LuaProcessorTest extends TestCase
2323
{
24-
use ClientMocking;
24+
use TestDoubleClient;
2525

2626
public function testProcessProcessesLuaExpression() : void
2727
{
2828
$luaExpression = 'a = 42';
2929

30-
$mockClient = $this->getMockClientBuilder()
30+
$mockClient = $this->getTestDoubleClientBuilder()
3131
->shouldHandle(
3232
new EvaluateRequest($luaExpression),
33-
DummyFactory::createEmptyResponse()
33+
TestDoubleFactory::createEmptyResponse()
3434
)
3535
->build();
3636

tests/Annotation/Processor/SqlProcessorTest.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,21 +17,21 @@
1717
use Tarantool\Client\Keys;
1818
use Tarantool\Client\Request\ExecuteRequest;
1919
use Tarantool\PhpUnit\Annotation\Processor\SqlProcessor;
20-
use Tarantool\PhpUnit\Client\ClientMocking;
21-
use Tarantool\PhpUnit\Client\DummyFactory;
20+
use Tarantool\PhpUnit\Client\TestDoubleClient;
21+
use Tarantool\PhpUnit\Client\TestDoubleFactory;
2222

2323
final class SqlProcessorTest extends TestCase
2424
{
25-
use ClientMocking;
25+
use TestDoubleClient;
2626

2727
public function testProcessProcessesSqlStatement() : void
2828
{
2929
$sqlStatement = 'INSERT INTO foo VALUES (1)';
3030

31-
$mockClient = $this->getMockClientBuilder()
31+
$mockClient = $this->getTestDoubleClientBuilder()
3232
->shouldHandle(
3333
ExecuteRequest::fromSql($sqlStatement),
34-
DummyFactory::createResponse([Keys::SQL_INFO => []])
34+
TestDoubleFactory::createResponse([Keys::SQL_INFO => []])
3535
)
3636
->build();
3737

0 commit comments

Comments
 (0)