Skip to content
Merged
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
5 changes: 2 additions & 3 deletions src/SimpleFactory/Sample/Driver/DriverInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,12 @@
* Created by PhpStorm.
* User: sockstack
* Date: 2018/11/7
* Time: 23:40
* Time: 23:40.
*/

namespace Sockstack\DesignPattern\SimpleFactory\Sample\Driver;


interface DriverInterface
{
public function connection();
}
}
6 changes: 2 additions & 4 deletions src/SimpleFactory/Sample/Driver/MysqlDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,15 @@
* Created by PhpStorm.
* User: sockstack
* Date: 2018/11/7
* Time: 23:40
* Time: 23:40.
*/

namespace Sockstack\DesignPattern\SimpleFactory\Sample\Driver;


class MysqlDriver implements DriverInterface
{

public function connection()
{
// TODO: Implement connection() method.
}
}
}
6 changes: 2 additions & 4 deletions src/SimpleFactory/Sample/Driver/MysqliDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,15 @@
* Created by PhpStorm.
* User: sockstack
* Date: 2018/11/7
* Time: 23:41
* Time: 23:41.
*/

namespace Sockstack\DesignPattern\SimpleFactory\Sample\Driver;


class MysqliDriver implements DriverInterface
{

public function connection()
{
// TODO: Implement connection() method.
}
}
}
9 changes: 5 additions & 4 deletions src/SimpleFactory/Sample/SimpleFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,19 @@
* Created by PhpStorm.
* User: sockstack
* Date: 2018/11/7
* Time: 23:34
* Time: 23:34.
*/

namespace Sockstack\DesignPattern\SimpleFactory\Sample;


use Sockstack\DesignPattern\SimpleFactory\Sample\Driver\MysqlDriver;
use Sockstack\DesignPattern\SimpleFactory\Sample\Driver\MysqliDriver;

class SimpleFactory
{
/**
* 返回mysql实例
* 返回mysql实例.
*
* @return MysqlDriver
*/
public static function createMysql()
Expand All @@ -24,7 +24,8 @@ public static function createMysql()
}

/**
* 返回mysqli实例
* 返回mysqli实例.
*
* @return MysqliDriver
*/
public static function createMysqli()
Expand Down
11 changes: 5 additions & 6 deletions tests/SimpleFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,14 @@
* Created by PhpStorm.
* User: sockstack
* Date: 2018/11/7
* Time: 23:43
* Time: 23:43.
*/

namespace Sockstack\DesignPattern\Test;


use PHPUnit\Framework\TestCase;
use Sockstack\DesignPattern\SimpleFactory\Sample\Driver\MysqliDriver;
use Sockstack\DesignPattern\SimpleFactory\Sample\Driver\MysqlDriver;
use Sockstack\DesignPattern\SimpleFactory\Sample\Driver\MysqliDriver;
use Sockstack\DesignPattern\SimpleFactory\Sample\SimpleFactory;

class SimpleFactoryTest extends TestCase
Expand All @@ -20,12 +19,12 @@ public function testSimpleFactory()
{
$mysql = SimpleFactory::createMysql();
if (!$mysql instanceof MysqlDriver) {
$this->fail("创建实例对象失败");
$this->fail('创建实例对象失败');
}

$mysqli = SimpleFactory::createMysqli();
if (!$mysqli instanceof MysqliDriver) {
$this->fail("创建实例对象失败");
$this->fail('创建实例对象失败');
}
}
}
}