Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit d371004

Browse filesBrowse files
committed
Rename factories names
1 parent 668c870 commit d371004
Copy full SHA for d371004

File tree

6 files changed

+104
-33
lines changed
Filter options

6 files changed

+104
-33
lines changed

‎src/Symfony/Component/Dsn/ConnectionFactory.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Dsn/ConnectionFactory.php
+5-5Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212
namespace Symfony\Component\Dsn;
1313

1414
use Symfony\Component\Dsn\Exception\InvalidArgumentException;
15-
use Symfony\Component\Dsn\Factory\MemcachedConnectionFactory;
16-
use Symfony\Component\Dsn\Factory\RedisConnectionFactory;
15+
use Symfony\Component\Dsn\Factory\MemcachedFactory;
16+
use Symfony\Component\Dsn\Factory\RedisFactory;
1717

1818
/**
1919
* Factory for undetermined Dsn.
@@ -53,13 +53,13 @@ public static function getType($dsn)
5353
*
5454
* @return mixed
5555
*/
56-
public static function createConnection($dsn, array $options = array())
56+
public static function create($dsn, array $options = array())
5757
{
5858
switch (static::getType($dsn)) {
5959
case static::TYPE_REDIS:
60-
return RedisConnectionFactory::createConnection($dsn, $options);
60+
return RedisFactory::create($dsn, $options);
6161
case static::TYPE_MEMCACHED:
62-
return MemcachedConnectionFactory::createConnection($dsn, $options);
62+
return MemcachedFactory::create($dsn, $options);
6363
default:
6464
throw new InvalidArgumentException(sprintf('Unsupported Dsn: %s.', $dsn));
6565
}

‎src/Symfony/Component/Dsn/Factory/MemcachedConnectionFactory.php renamed to ‎src/Symfony/Component/Dsn/Factory/MemcachedFactory.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Dsn/Factory/MemcachedFactory.php
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
*
1919
* @author Nicolas Grekas <p@tchwork.com>
2020
*/
21-
class MemcachedConnectionFactory
21+
class MemcachedFactory
2222
{
2323
private static $defaultClientOptions = array(
2424
'class' => null,
@@ -49,7 +49,7 @@ class MemcachedConnectionFactory
4949
*
5050
* @throws \ErrorException When invalid options or servers are provided
5151
*/
52-
public static function createConnection($dsns, array $options = array())
52+
public static function create($dsns, array $options = array())
5353
{
5454
set_error_handler(function ($type, $msg, $file, $line) { throw new \ErrorException($msg, 0, $type, $file, $line); });
5555
try {

‎src/Symfony/Component/Dsn/Factory/RedisConnectionFactory.php renamed to ‎src/Symfony/Component/Dsn/Factory/RedisFactory.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Dsn/Factory/RedisFactory.php
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
*
1919
* @author Nicolas Grekas <p@tchwork.com>
2020
*/
21-
class RedisConnectionFactory
21+
class RedisFactory
2222
{
2323
private static $defaultConnectionOptions = array(
2424
'class' => null,
@@ -46,7 +46,7 @@ class RedisConnectionFactory
4646
*
4747
* @return \Redis|\Predis\Client According to the "class" option
4848
*/
49-
public static function createConnection($dsn, array $options = array())
49+
public static function create($dsn, array $options = array())
5050
{
5151
if (0 !== strpos($dsn, 'redis://')) {
5252
throw new InvalidArgumentException(sprintf('Invalid Redis DSN: %s does not start with "redis://"', $dsn));
+71Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
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\Dsn\Tests\Adapter;
13+
14+
use PHPUnit\Framework\TestCase;
15+
use Symfony\Component\Dsn\ConnectionFactory;
16+
use Symfony\Component\Dsn\Exception\InvalidArgumentException;
17+
use Symfony\Component\Dsn\Factory\RedisFactory;
18+
19+
/**
20+
* @requires extension redis
21+
* @requires extension memcached
22+
*/
23+
class ConnectionFactoryTest extends TestCase
24+
{
25+
/**
26+
* @dataProvider provideValidDsn
27+
*/
28+
public function testGetType($dsn, $type)
29+
{
30+
$this->assertSame($type, ConnectionFactory::getType($dsn));
31+
}
32+
33+
/**
34+
* @dataProvider provideInvalidDsn
35+
* @expectedException InvalidArgumentException
36+
*/
37+
public function testGetTypeInvalid($dsn)
38+
{
39+
ConnectionFactory::getType($dsn);
40+
}
41+
42+
/**
43+
* @dataProvider provideValidDsn
44+
*/
45+
public function testCreate($dsn, $type, $objectClass)
46+
{
47+
$this->assertInstanceOf($objectClass, ConnectionFactory::create($dsn));
48+
}
49+
50+
/**
51+
* @dataProvider provideInvalidDsn
52+
* @expectedException InvalidArgumentException
53+
*/
54+
public function testCreateInvalid($dsn)
55+
{
56+
ConnectionFactory::create($dsn);
57+
}
58+
59+
public function provideValidDsn()
60+
{
61+
yield array('redis://localhost', ConnectionFactory::TYPE_REDIS, \Redis::class);
62+
yield array('memcached://localhost', ConnectionFactory::TYPE_MEMCACHED, \Memcached::class);
63+
}
64+
65+
public function provideInvalidDsn()
66+
{
67+
yield array(array('http://localhost'));
68+
yield array('http://localhost');
69+
yield array('mysql://localhost');
70+
}
71+
}

‎src/Symfony/Component/Dsn/Tests/Factory/MemcachedConnectionFactoryTest.php renamed to ‎src/Symfony/Component/Dsn/Tests/Factory/MemcachedFactoryTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Dsn/Tests/Factory/MemcachedFactoryTest.php
+8-8Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,16 @@
1212
namespace Symfony\Component\Cache\Tests\Adapter;
1313

1414
use PHPUnit\Framework\TestCase;
15-
use Symfony\Component\Dsn\Factory\MemcachedConnectionFactory;
15+
use Symfony\Component\Dsn\Factory\MemcachedFactory;
1616

1717
/**
1818
* @requires extension memcached
1919
*/
20-
class MemcachedConnectionFactoryTest extends TestCase
20+
class MemcachedFactoryTest extends TestCase
2121
{
2222
public function testOptions()
2323
{
24-
$client = MemcachedConnectionFactory::createConnection(array(), array(
24+
$client = MemcachedFactory::create(array(), array(
2525
'libketama_compatible' => false,
2626
'distribution' => 'modula',
2727
'compression' => true,
@@ -45,7 +45,7 @@ public function testOptions()
4545
*/
4646
public function testBadOptions($name, $value)
4747
{
48-
MemcachedConnectionFactory::createConnection(array(), array($name => $value));
48+
MemcachedFactory::create(array(), array($name => $value));
4949
}
5050

5151
public function provideBadOptions()
@@ -60,7 +60,7 @@ public function provideBadOptions()
6060

6161
public function testDefaultOptions()
6262
{
63-
$client = MemcachedConnectionFactory::createConnection(array());
63+
$client = MemcachedFactory::create(array());
6464

6565
$this->assertTrue($client->getOption(\Memcached::OPT_COMPRESSION));
6666
$this->assertSame(1, $client->getOption(\Memcached::OPT_BINARY_PROTOCOL));
@@ -72,8 +72,8 @@ public function testDefaultOptions()
7272
*/
7373
public function testServersSetting($dsn, $host, $port)
7474
{
75-
$client1 = MemcachedConnectionFactory::createConnection($dsn);
76-
$client2 = MemcachedConnectionFactory::createConnection(array($dsn));
75+
$client1 = MemcachedFactory::create($dsn);
76+
$client2 = MemcachedFactory::create(array($dsn));
7777
$expect = array(
7878
'host' => $host,
7979
'port' => $port,
@@ -127,7 +127,7 @@ public function provideServersSetting()
127127
*/
128128
public function testDsnWithOptions($dsn, array $options, array $expectedOptions)
129129
{
130-
$client = MemcachedConnectionFactory::createConnection($dsn, $options);
130+
$client = MemcachedFactory::create($dsn, $options);
131131

132132
foreach ($expectedOptions as $option => $expect) {
133133
$this->assertSame($expect, $client->getOption($option));

‎src/Symfony/Component/Dsn/Tests/Factory/RedisConnectionFactoryTest.php renamed to ‎src/Symfony/Component/Dsn/Tests/Factory/RedisFactoryTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Dsn/Tests/Factory/RedisFactoryTest.php
+16-16Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -12,46 +12,46 @@
1212
namespace Symfony\Component\Dsn\Tests\Adapter;
1313

1414
use PHPUnit\Framework\TestCase;
15-
use Symfony\Component\Dsn\Factory\RedisConnectionFactory;
15+
use Symfony\Component\Dsn\Factory\RedisFactory;
1616

1717
/**
1818
* @requires extension redis
1919
*/
20-
class RedisConnectionFactoryTest extends TestCase
20+
class RedisFactoryTest extends TestCase
2121
{
22-
public function testCreateConnection()
22+
public function testCreate()
2323
{
2424
$redisHost = getenv('REDIS_HOST');
2525

26-
$redis = RedisConnectionFactory::createConnection('redis://'.$redisHost);
26+
$redis = RedisFactory::create('redis://'.$redisHost);
2727
$this->assertInstanceOf(\Redis::class, $redis);
2828
$this->assertTrue($redis->isConnected());
2929
$this->assertSame(0, $redis->getDbNum());
3030

31-
$redis = RedisConnectionFactory::createConnection('redis://'.$redisHost.'/2');
31+
$redis = RedisFactory::create('redis://'.$redisHost.'/2');
3232
$this->assertSame(2, $redis->getDbNum());
3333

34-
$redis = RedisConnectionFactory::createConnection('redis://'.$redisHost, array('timeout' => 3));
34+
$redis = RedisFactory::create('redis://'.$redisHost, array('timeout' => 3));
3535
$this->assertEquals(3, $redis->getTimeout());
3636

37-
$redis = RedisConnectionFactory::createConnection('redis://'.$redisHost.'?timeout=4');
37+
$redis = RedisFactory::create('redis://'.$redisHost.'?timeout=4');
3838
$this->assertEquals(4, $redis->getTimeout());
3939

40-
$redis = RedisConnectionFactory::createConnection('redis://'.$redisHost, array('read_timeout' => 5));
40+
$redis = RedisFactory::create('redis://'.$redisHost, array('read_timeout' => 5));
4141
$this->assertEquals(5, $redis->getReadTimeout());
4242
}
4343

4444
/**
45-
* @dataProvider provideFailedCreateConnection
45+
* @dataProvider provideFailedCreate
4646
* @expectedException \Symfony\Component\Dsn\Exception\InvalidArgumentException
4747
* @expectedExceptionMessage Redis connection failed
4848
*/
49-
public function testFailedCreateConnection($dsn)
49+
public function testFailedCreate($dsn)
5050
{
51-
RedisConnectionFactory::createConnection($dsn);
51+
RedisFactory::create($dsn);
5252
}
5353

54-
public function provideFailedCreateConnection()
54+
public function provideFailedCreate()
5555
{
5656
return array(
5757
array('redis://localhost:1234'),
@@ -61,16 +61,16 @@ public function provideFailedCreateConnection()
6161
}
6262

6363
/**
64-
* @dataProvider provideInvalidCreateConnection
64+
* @dataProvider provideInvalidCreate
6565
* @expectedException \Symfony\Component\Dsn\Exception\InvalidArgumentException
6666
* @expectedExceptionMessage Invalid Redis DSN
6767
*/
68-
public function testInvalidCreateConnection($dsn)
68+
public function testInvalidCreate($dsn)
6969
{
70-
RedisConnectionFactory::createConnection($dsn);
70+
RedisFactory::create($dsn);
7171
}
7272

73-
public function provideInvalidCreateConnection()
73+
public function provideInvalidCreate()
7474
{
7575
return array(
7676
array('foo://localhost'),

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.