Skip to content

Commit 4072090

Browse files
[Tests] Migrate tests to static data providers
1 parent 0463b6a commit 4072090

File tree

4 files changed

+118
-15
lines changed

4 files changed

+118
-15
lines changed
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
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 Symfony\Component\Lock\Tests\Store;
13+
14+
use PHPUnit\Framework\TestCase;
15+
use Symfony\Component\Lock\Store\MongoDbStore;
16+
use Symfony\Component\Lock\Store\StoreFactory;
17+
18+
/**
19+
* @author Alexandre Daubois <alex.daubois@gmail.com>
20+
*
21+
* @requires extension mongo
22+
*/
23+
class MongoDbStoreFactoryTest extends TestCase
24+
{
25+
public function testCreateMongoDbCollectionStore()
26+
{
27+
$store = StoreFactory::createStore($this->createMock(\MongoDB\Collection::class));
28+
29+
$this->assertInstanceOf(MongoDbStore::class, $store);
30+
}
31+
32+
public function testCreateMongoDbCollectionStoreAsDsn()
33+
{
34+
$store = StoreFactory::createStore('mongodb://localhost/test?collection=lock');
35+
36+
$this->assertInstanceOf(MongoDbStore::class, $store);
37+
}
38+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
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 Symfony\Component\Lock\Tests\Store;
13+
14+
use PHPUnit\Framework\TestCase;
15+
use Symfony\Component\Cache\Traits\RedisProxy;
16+
use Symfony\Component\Lock\Store\RedisStore;
17+
use Symfony\Component\Lock\Store\StoreFactory;
18+
19+
/**
20+
* @author Alexandre Daubois <alex.daubois@gmail.com>
21+
*/
22+
class RedisProxyStoreFactoryTest extends TestCase
23+
{
24+
public function testCreateStore()
25+
{
26+
if (!class_exists(RedisProxy::class)) {
27+
$this->markTestSkipped();
28+
}
29+
30+
$store = StoreFactory::createStore($this->createMock(RedisProxy::class));
31+
32+
$this->assertInstanceOf(RedisStore::class, $store);
33+
}
34+
}

Tests/Store/StoreFactoryTest.php

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -15,19 +15,16 @@
1515
use PHPUnit\Framework\TestCase;
1616
use Symfony\Component\Cache\Adapter\AbstractAdapter;
1717
use Symfony\Component\Cache\Adapter\MemcachedAdapter;
18-
use Symfony\Component\Cache\Traits\RedisProxy;
1918
use Symfony\Component\Lock\Store\DoctrineDbalPostgreSqlStore;
2019
use Symfony\Component\Lock\Store\DoctrineDbalStore;
2120
use Symfony\Component\Lock\Store\FlockStore;
2221
use Symfony\Component\Lock\Store\InMemoryStore;
2322
use Symfony\Component\Lock\Store\MemcachedStore;
24-
use Symfony\Component\Lock\Store\MongoDbStore;
2523
use Symfony\Component\Lock\Store\PdoStore;
2624
use Symfony\Component\Lock\Store\PostgreSqlStore;
2725
use Symfony\Component\Lock\Store\RedisStore;
2826
use Symfony\Component\Lock\Store\SemaphoreStore;
2927
use Symfony\Component\Lock\Store\StoreFactory;
30-
use Symfony\Component\Lock\Store\ZookeeperStore;
3128

3229
/**
3330
* @author Jérémy Derussé <jeremy@derusse.com>
@@ -44,26 +41,15 @@ public function testCreateStore($connection, string $expectedStoreClass)
4441
$this->assertInstanceOf($expectedStoreClass, $store);
4542
}
4643

47-
public function validConnections()
44+
public static function validConnections(): \Generator
4845
{
4946
if (class_exists(\Redis::class)) {
5047
yield [new \Redis(), RedisStore::class];
5148
}
52-
if (class_exists(RedisProxy::class)) {
53-
yield [$this->createMock(RedisProxy::class), RedisStore::class];
54-
}
5549
yield [new \Predis\Client(), RedisStore::class];
5650
if (class_exists(\Memcached::class)) {
5751
yield [new \Memcached(), MemcachedStore::class];
5852
}
59-
if (class_exists(\MongoDB\Collection::class)) {
60-
yield [$this->createMock(\MongoDB\Collection::class), MongoDbStore::class];
61-
yield ['mongodb://localhost/test?collection=lock', MongoDbStore::class];
62-
}
63-
if (class_exists(\Zookeeper::class)) {
64-
yield [$this->createMock(\Zookeeper::class), ZookeeperStore::class];
65-
yield ['zookeeper://localhost:2181', ZookeeperStore::class];
66-
}
6753
if (\extension_loaded('sysvsem')) {
6854
yield ['semaphore', SemaphoreStore::class];
6955
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
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 Symfony\Component\Lock\Tests\Store;
13+
14+
use PHPUnit\Framework\TestCase;
15+
use Symfony\Component\Lock\Store\StoreFactory;
16+
use Symfony\Component\Lock\Store\ZookeeperStore;
17+
18+
/**
19+
* @author Alexandre Daubois <alex.daubois@gmail.com>
20+
*
21+
* @requires extension zookeeper
22+
*/
23+
class ZookeeperStoreFactoryTest extends TestCase
24+
{
25+
public function testCreateZooKeeperStore()
26+
{
27+
$store = StoreFactory::createStore($this->createMock(\Zookeeper::class));
28+
29+
$this->assertInstanceOf(ZookeeperStore::class, $store);
30+
}
31+
32+
public function testCreateZooKeeperStoreAsDsn()
33+
{
34+
$store = StoreFactory::createStore('zookeeper://localhost:2181');
35+
36+
$this->assertInstanceOf(ZookeeperStore::class, $store);
37+
}
38+
39+
public function testCreateZooKeeperStoreWithMultipleHosts()
40+
{
41+
$store = StoreFactory::createStore('zookeeper://localhost01,localhost02:2181');
42+
43+
$this->assertInstanceOf(ZookeeperStore::class, $store);
44+
}
45+
}

0 commit comments

Comments
 (0)