提交的内容

This commit is contained in:
2025-05-12 15:45:02 +08:00
parent 629c4750da
commit b48c692775
3043 changed files with 34732 additions and 60810 deletions

1
vendor/topthink/framework/tests/AppTest.php vendored Executable file → Normal file
View File

@ -148,6 +148,7 @@ class AppTest extends TestCase
$env->shouldReceive('load')->once()->with($rootPath . '.env');
$env->shouldReceive('get')->once()->with('config_ext', '.php')->andReturn('.php');
$env->shouldReceive('get')->once()->with('app_debug')->andReturn($debug);
$env->shouldReceive('get')->once()->with('env_name', '')->andReturn('');
$event = m::mock(Event::class);
$event->shouldReceive('trigger')->once()->with(AppInit::class);

2
vendor/topthink/framework/tests/CacheTest.php vendored Executable file → Normal file
View File

@ -83,9 +83,9 @@ class CacheTest extends TestCase
$this->assertTrue($this->cache->get('bar'));
$this->cache->set('baz', null);
$this->assertTrue($this->cache->has('baz'));
$this->assertNull($this->cache->get('baz'));
$this->assertTrue($this->cache->has('baz'));
$this->cache->delete('baz');
$this->assertFalse($this->cache->has('baz'));
$this->assertNull($this->cache->get('baz'));

0
vendor/topthink/framework/tests/ConfigTest.php vendored Executable file → Normal file
View File

View File

@ -1,314 +0,0 @@
<?php
namespace think\tests;
use PHPUnit\Framework\TestCase;
use ReflectionMethod;
use stdClass;
use think\Container;
use think\exception\ClassNotFoundException;
use think\exception\FuncNotFoundException;
class Taylor
{
public $name;
public function __construct($name)
{
$this->name = $name;
}
public function some(Container $container)
{
}
protected function protectionFun()
{
return true;
}
public static function test(Container $container)
{
return $container;
}
public static function __make()
{
return new self('Taylor');
}
}
class SomeClass
{
public $container;
public $count = 0;
public function __construct(Container $container)
{
$this->container = $container;
}
}
class ContainerTest extends TestCase
{
protected function tearDown(): void
{
Container::setInstance(null);
}
public function testClosureResolution()
{
$container = new Container;
Container::setInstance($container);
$container->bind('name', function () {
return 'Taylor';
});
$this->assertEquals('Taylor', $container->make('name'));
$this->assertEquals('Taylor', Container::pull('name'));
}
public function testGet()
{
$container = new Container;
$this->expectException(ClassNotFoundException::class);
$this->expectExceptionMessage('class not exists: name');
$container->get('name');
$container->bind('name', function () {
return 'Taylor';
});
$this->assertSame('Taylor', $container->get('name'));
}
public function testExist()
{
$container = new Container;
$container->bind('name', function () {
return 'Taylor';
});
$this->assertFalse($container->exists("name"));
$container->make('name');
$this->assertTrue($container->exists('name'));
}
public function testInstance()
{
$container = new Container;
$container->bind('name', function () {
return 'Taylor';
});
$this->assertEquals('Taylor', $container->get('name'));
$container->bind('name2', Taylor::class);
$object = new stdClass();
$this->assertFalse($container->exists('name2'));
$container->instance('name2', $object);
$this->assertTrue($container->exists('name2'));
$this->assertTrue($container->exists(Taylor::class));
$this->assertEquals($object, $container->make(Taylor::class));
unset($container->name1);
$this->assertFalse($container->exists('name1'));
$container->delete('name2');
$this->assertFalse($container->exists('name2'));
foreach ($container as $class => $instance) {
}
}
public function testBind()
{
$container = new Container;
$object = new stdClass();
$container->bind(['name' => Taylor::class]);
$container->bind('name2', $object);
$container->bind('name3', Taylor::class);
$container->bind('name3', Taylor::class);
$container->name4 = $object;
$container['name5'] = $object;
$this->assertTrue(isset($container->name4));
$this->assertTrue(isset($container['name5']));
$this->assertInstanceOf(Taylor::class, $container->get('name'));
$this->assertSame($object, $container->get('name2'));
$this->assertSame($object, $container->name4);
$this->assertSame($object, $container['name5']);
$this->assertInstanceOf(Taylor::class, $container->get('name3'));
unset($container['name']);
$this->assertFalse(isset($container['name']));
unset($container->name3);
$this->assertFalse(isset($container->name3));
}
public function testAutoConcreteResolution()
{
$container = new Container;
$taylor = $container->make(Taylor::class);
$this->assertInstanceOf(Taylor::class, $taylor);
$this->assertSame('Taylor', $taylor->name);
}
public function testGetAndSetInstance()
{
$this->assertInstanceOf(Container::class, Container::getInstance());
$object = new stdClass();
Container::setInstance($object);
$this->assertSame($object, Container::getInstance());
Container::setInstance(function () {
return $this;
});
$this->assertSame($this, Container::getInstance());
}
public function testResolving()
{
$container = new Container();
$container->bind(Container::class, $container);
$container->resolving(function (SomeClass $taylor, Container $container) {
$taylor->count++;
});
$container->resolving(SomeClass::class, function (SomeClass $taylor, Container $container) {
$taylor->count++;
});
/** @var SomeClass $someClass */
$someClass = $container->invokeClass(SomeClass::class);
$this->assertEquals(2, $someClass->count);
}
public function testInvokeFunctionWithoutMethodThrowsException()
{
$this->expectException(FuncNotFoundException::class);
$this->expectExceptionMessage('function not exists: ContainerTestCallStub()');
$container = new Container();
$container->invokeFunction('ContainerTestCallStub', []);
}
public function testInvokeProtectionMethod()
{
$container = new Container();
$this->assertTrue($container->invokeMethod([Taylor::class, 'protectionFun'], [], true));
}
public function testInvoke()
{
$container = new Container();
Container::setInstance($container);
$container->bind(Container::class, $container);
$stub = $this->createMock(Taylor::class);
$stub->expects($this->once())->method('some')->with($container)->will($this->returnSelf());
$container->invokeMethod([$stub, 'some']);
$this->assertEquals('48', $container->invoke('ord', ['0']));
$this->assertSame($container, $container->invoke(Taylor::class . '::test', []));
$this->assertSame($container, $container->invokeMethod(Taylor::class . '::test'));
$reflect = new ReflectionMethod($container, 'exists');
$this->assertTrue($container->invokeReflectMethod($container, $reflect, [Container::class]));
$this->assertSame($container, $container->invoke(function (Container $container) {
return $container;
}));
$this->assertSame($container, $container->invoke(Taylor::class . '::test'));
$object = $container->invokeClass(SomeClass::class);
$this->assertInstanceOf(SomeClass::class, $object);
$this->assertSame($container, $object->container);
$stdClass = new stdClass();
$container->invoke(function (Container $container, stdClass $stdObject, $key1, $lowKey, $key2 = 'default') use ($stdClass) {
$this->assertEquals('value1', $key1);
$this->assertEquals('default', $key2);
$this->assertEquals('value2', $lowKey);
$this->assertSame($stdClass, $stdObject);
return $container;
}, ['some' => $stdClass, 'key1' => 'value1', 'low_key' => 'value2']);
}
public function testInvokeMethodNotExists()
{
$container = $this->resolveContainer();
$this->expectException(FuncNotFoundException::class);
$container->invokeMethod([SomeClass::class, 'any']);
}
public function testInvokeClassNotExists()
{
$container = new Container();
Container::setInstance($container);
$container->bind(Container::class, $container);
$this->expectExceptionObject(new ClassNotFoundException('class not exists: SomeClass'));
$container->invokeClass('SomeClass');
}
protected function resolveContainer()
{
$container = new Container();
Container::setInstance($container);
return $container;
}
}

0
vendor/topthink/framework/tests/DbTest.php vendored Executable file → Normal file
View File

0
vendor/topthink/framework/tests/DispatchTest.php vendored Executable file → Normal file
View File

0
vendor/topthink/framework/tests/EnvTest.php vendored Executable file → Normal file
View File

0
vendor/topthink/framework/tests/EventTest.php vendored Executable file → Normal file
View File

2
vendor/topthink/framework/tests/HttpTest.php vendored Executable file → Normal file
View File

@ -54,8 +54,6 @@ class HttpTest extends TestCase
return $req === $request;
})->andReturn($response);
$route->shouldReceive('config')->with('route_annotation')->andReturn(true);
$this->app->shouldReceive('get')->with('route')->andReturn($route);
$console = m::mock(Console::class);

0
vendor/topthink/framework/tests/InteractsWithApp.php vendored Executable file → Normal file
View File

0
vendor/topthink/framework/tests/LogTest.php vendored Executable file → Normal file
View File

0
vendor/topthink/framework/tests/MiddlewareTest.php vendored Executable file → Normal file
View File

63
vendor/topthink/framework/tests/RouteTest.php vendored Executable file → Normal file
View File

@ -6,7 +6,6 @@ use Closure;
use Mockery as m;
use Mockery\MockInterface;
use PHPUnit\Framework\TestCase;
use think\exception\RouteNotFoundException;
use think\helper\Str;
use think\Request;
use think\response\Redirect;
@ -76,53 +75,21 @@ class RouteTest extends TestCase
$this->assertEquals('get-foo', $response->getContent());
}
// public function testOptionsRequest()
// {
// $this->route->get('foo', function () {
// return 'get-foo';
// });
//
// $this->route->put('foo', function () {
// return 'put-foo';
// });
//
// $this->route->group(function () {
// $this->route->post('foo', function () {
// return 'post-foo';
// });
// });
// $this->route->group('abc', function () {
// $this->route->post('foo/:id', function () {
// return 'post-abc-foo';
// });
// });
//
// $this->route->post('foo/:id', function () {
// return 'post-abc-foo';
// });
//
// $this->route->resource('bar', 'SomeClass');
//
// $request = $this->makeRequest('foo', 'options');
// $response = $this->route->dispatch($request);
// $this->assertEquals(204, $response->getCode());
// $this->assertEquals('GET, PUT, POST', $response->getHeader('Allow'));
//
// $request = $this->makeRequest('bar', 'options');
// $response = $this->route->dispatch($request);
// $this->assertEquals(204, $response->getCode());
// $this->assertEquals('GET, POST', $response->getHeader('Allow'));
//
// $request = $this->makeRequest('bar/1', 'options');
// $response = $this->route->dispatch($request);
// $this->assertEquals(204, $response->getCode());
// $this->assertEquals('GET, PUT, DELETE', $response->getHeader('Allow'));
//
// $request = $this->makeRequest('xxxx', 'options');
// $response = $this->route->dispatch($request);
// $this->assertEquals(204, $response->getCode());
// $this->assertEquals('GET, POST, PUT, DELETE', $response->getHeader('Allow'));
// }
public function testGroup()
{
$this->route->group(function () {
$this->route->group('foo', function () {
$this->route->post('bar', function () {
return 'hello,world!';
});
});
});
$request = $this->makeRequest('foo/bar', 'post');
$response = $this->route->dispatch($request);
$this->assertEquals(200, $response->getCode());
$this->assertEquals('hello,world!', $response->getContent());
}
public function testAllowCrossDomain()
{

0
vendor/topthink/framework/tests/SessionTest.php vendored Executable file → Normal file
View File

0
vendor/topthink/framework/tests/UrlRouteTest.php vendored Executable file → Normal file
View File

7
vendor/topthink/framework/tests/ViewTest.php vendored Executable file → Normal file
View File

@ -70,7 +70,6 @@ class TestTemplate implements TemplateHandlerInterface
/**
* 检测是否存在模板文件
* @access public
* @param string $template 模板文件或者模板规则
* @return bool
*/
@ -81,7 +80,6 @@ class TestTemplate implements TemplateHandlerInterface
/**
* 渲染模板文件
* @access public
* @param string $template 模板文件
* @param array $data 模板变量
* @return void
@ -93,7 +91,6 @@ class TestTemplate implements TemplateHandlerInterface
/**
* 渲染模板内容
* @access public
* @param string $content 模板内容
* @param array $data 模板变量
* @return void
@ -105,7 +102,6 @@ class TestTemplate implements TemplateHandlerInterface
/**
* 配置模板引擎
* @access private
* @param array $config 参数
* @return void
*/
@ -116,9 +112,8 @@ class TestTemplate implements TemplateHandlerInterface
/**
* 获取模板引擎配置
* @access public
* @param string $name 参数名
* @return void
* @return mixed
*/
public function getConfig(string $name)
{

0
vendor/topthink/framework/tests/bootstrap.php vendored Executable file → Normal file
View File