Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
42 changes: 21 additions & 21 deletions tests/Pools/ConnectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,34 +22,34 @@ public function setUp(): void

public function testGetID(): void
{
$this->assertEquals(null, $this->object->getID());
$this->assertSame('', $this->object->getID());

$this->object->setID('test');

$this->assertEquals('test', $this->object->getID());
$this->assertSame('test', $this->object->getID());
}

public function testSetID(): void
{
$this->assertEquals(null, $this->object->getID());
$this->assertSame('', $this->object->getID());

$this->assertInstanceOf(Connection::class, $this->object->setID('test'));

$this->assertEquals('test', $this->object->getID());
$this->assertSame('test', $this->object->getID());
}

public function testGetResource(): void
{
$this->assertEquals('x', $this->object->getResource());
$this->assertSame('x', $this->object->getResource());
}

public function testSetResource(): void
{
$this->assertEquals('x', $this->object->getResource());
$this->assertSame('x', $this->object->getResource());

$this->assertInstanceOf(Connection::class, $this->object->setResource('y'));

$this->assertEquals('y', $this->object->getResource());
$this->assertSame('y', $this->object->getResource());
}

public function testSetPool(): void
Expand All @@ -74,30 +74,30 @@ public function testGetPool(): void
}

$this->assertInstanceOf(Pool::class, $pool);
$this->assertEquals('test', $pool->getName());
$this->assertSame('test', $pool->getName());
}

public function testReclaim(): void
{
$pool = new Pool('test', 2, fn () => 'x');

$this->assertEquals(2, $pool->count());
$this->assertSame(2, $pool->count());

$connection1 = $pool->pop();

$this->assertEquals(1, $pool->count());
$this->assertSame(1, $pool->count());

$connection2 = $pool->pop();

$this->assertEquals(0, $pool->count());
$this->assertSame(0, $pool->count());

$this->assertInstanceOf(Pool::class, $connection1->reclaim());

$this->assertEquals(1, $pool->count());
$this->assertSame(1, $pool->count());

$this->assertInstanceOf(Pool::class, $connection2->reclaim());

$this->assertEquals(2, $pool->count());
$this->assertSame(2, $pool->count());
}

public function testReclaimException(): void
Expand All @@ -114,27 +114,27 @@ public function testDestroy(): void
return $i <= 2 ? 'x' : 'y';
});

$this->assertEquals(2, $object->count());
$this->assertSame(2, $object->count());

$connection1 = $object->pop();
$connection2 = $object->pop();

$this->assertEquals(0, $object->count());
$this->assertSame(0, $object->count());

$this->assertEquals('x', $connection1->getResource());
$this->assertEquals('x', $connection2->getResource());
$this->assertSame('x', $connection1->getResource());
$this->assertSame('x', $connection2->getResource());

$connection1->destroy();
$connection2->destroy();

$this->assertEquals(2, $object->count());
$this->assertSame(2, $object->count());

$connection1 = $object->pop();
$connection2 = $object->pop();

$this->assertEquals(0, $object->count());
$this->assertSame(0, $object->count());

$this->assertEquals('y', $connection1->getResource());
$this->assertEquals('y', $connection2->getResource());
$this->assertSame('y', $connection1->getResource());
$this->assertSame('y', $connection2->getResource());
}
}
36 changes: 18 additions & 18 deletions tests/Pools/GroupTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,39 +52,39 @@ public function testReset(): void
{
$this->object->add(new Pool('test', 5, fn () => 'x'));

$this->assertEquals(5, $this->object->get('test')->count());
$this->assertSame(5, $this->object->get('test')->count());

$this->object->get('test')->pop();
$this->object->get('test')->pop();
$this->object->get('test')->pop();

$this->assertEquals(2, $this->object->get('test')->count());
$this->assertSame(2, $this->object->get('test')->count());

$this->object->reclaim();

$this->assertEquals(5, $this->object->get('test')->count());
$this->assertSame(5, $this->object->get('test')->count());
}

public function testReconnectAttempts(): void
{
$this->object->add(new Pool('test', 5, fn () => 'x'));

$this->assertEquals(3, $this->object->get('test')->getReconnectAttempts());
$this->assertSame(3, $this->object->get('test')->getReconnectAttempts());

$this->object->setReconnectAttempts(5);

$this->assertEquals(5, $this->object->get('test')->getReconnectAttempts());
$this->assertSame(5, $this->object->get('test')->getReconnectAttempts());
}

public function testReconnectSleep(): void
{
$this->object->add(new Pool('test', 5, fn () => 'x'));

$this->assertEquals(1, $this->object->get('test')->getReconnectSleep());
$this->assertSame(1, $this->object->get('test')->getReconnectSleep());

$this->object->setReconnectSleep(2);

$this->assertEquals(2, $this->object->get('test')->getReconnectSleep());
$this->assertSame(2, $this->object->get('test')->getReconnectSleep());
}

public function testUse(): void
Expand All @@ -97,22 +97,22 @@ public function testUse(): void
$this->object->add($pool2);
$this->object->add($pool3);

$this->assertEquals(1, $pool1->count());
$this->assertEquals(1, $pool2->count());
$this->assertEquals(1, $pool3->count());
$this->assertSame(1, $pool1->count());
$this->assertSame(1, $pool2->count());
$this->assertSame(1, $pool3->count());

// @phpstan-ignore argument.type
$this->object->use(['pool1', 'pool3'], function ($one, $three) use ($pool1, $pool2, $pool3): void {
$this->assertEquals('1', $one);
$this->assertEquals('3', $three);
$this->assertSame('1', $one);
$this->assertSame('3', $three);

$this->assertEquals(0, $pool1->count());
$this->assertEquals(1, $pool2->count());
$this->assertEquals(0, $pool3->count());
$this->assertSame(0, $pool1->count());
$this->assertSame(1, $pool2->count());
$this->assertSame(0, $pool3->count());
});

$this->assertEquals(1, $pool1->count());
$this->assertEquals(1, $pool2->count());
$this->assertEquals(1, $pool3->count());
$this->assertSame(1, $pool1->count());
$this->assertSame(1, $pool2->count());
$this->assertSame(1, $pool3->count());
}
}
Loading