designModeDemo/demo/Creational/Singleton/Tests/SingletonTest.php

20 lines
594 B
PHP

<?php
namespace demo\Creational\Singleton\Tests;
use demo\Creational\Singleton\Singleton;
use PHPUnit\Framework\TestCase;
class SingletonTest extends TestCase
{
public function testUniqueness()
{
$firstCall = Singleton::getInstance();
$secondCall = Singleton::getInstance();
// 断言变量属于给定类型
$this->assertInstanceOf(Singleton::class, $firstCall);
// 断言两个变量具有相同的类型和值。 用于对象,它断言两个变量引用同一个对象
$this->assertSame($firstCall, $secondCall);
}
}