添加网站文件
This commit is contained in:
29
vendor/songshenzong/support/tests/Core/EchoBashTest.php
vendored
Normal file
29
vendor/songshenzong/support/tests/Core/EchoBashTest.php
vendored
Normal file
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
namespace Songshenzong\Support\Test\Core;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* Class EchoBashTest
|
||||
*
|
||||
* @package Songshenzong\Support\Test\Core
|
||||
*/
|
||||
class EchoBashTest extends TestCase
|
||||
{
|
||||
|
||||
/**
|
||||
* @throws \PHPUnit\Framework\ExpectationFailedException
|
||||
* @throws \SebastianBergmann\RecursionContext\InvalidArgumentException
|
||||
*/
|
||||
public function testIsJson()
|
||||
{
|
||||
echoRed('echo Red');
|
||||
echoPurple('echo Purple');
|
||||
echoGreen('echo Green');
|
||||
echoCyan('echo Cyan');
|
||||
echoBrown('echo Brown');
|
||||
echoBlue('echo Blue');
|
||||
$this->assertEquals(true, true);
|
||||
}
|
||||
}
|
||||
108
vendor/songshenzong/support/tests/Core/StrTest.php
vendored
Normal file
108
vendor/songshenzong/support/tests/Core/StrTest.php
vendored
Normal file
@@ -0,0 +1,108 @@
|
||||
<?php
|
||||
|
||||
namespace Songshenzong\Support\Test\Core;
|
||||
|
||||
use stdClass;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Songshenzong\Support\Strings;
|
||||
|
||||
/**
|
||||
* Class StrTest
|
||||
*
|
||||
* @package Songshenzong\Support\Test\Core
|
||||
*/
|
||||
class StrTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $xmlString = <<<ETO
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<books>
|
||||
<book>
|
||||
<author>Jack Herrington</author>
|
||||
<title>PHP Hacks</title>
|
||||
<publisher>O'Reilly</publisher>
|
||||
</book>
|
||||
<book>
|
||||
<author>Jack Herrington</author>
|
||||
<title>Podcasting Hacks</title>
|
||||
<publisher>O'Reilly</publisher>
|
||||
</book>
|
||||
</books>
|
||||
ETO;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $jsonString = '{ "tools": [ { "name":"css format" , "site":"https://songshenzong.com" }, { "name":"pwd check" , "site":"https://songshenzong.com" } ] }';
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected $simpleJsonArray = ['json' => true];
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $simpleJsonString = '{"json":true}';
|
||||
|
||||
/**
|
||||
* @throws \PHPUnit\Framework\ExpectationFailedException
|
||||
* @throws \SebastianBergmann\RecursionContext\InvalidArgumentException
|
||||
*/
|
||||
public function testIsJson()
|
||||
{
|
||||
$this->assertEquals(false, Strings::isJson());
|
||||
$this->assertEquals(false, Strings::isJson(''));
|
||||
$this->assertEquals(false, Strings::isJson($this->xmlString));
|
||||
$this->assertEquals(true, Strings::isJson($this->simpleJsonString));
|
||||
$this->assertEquals(true, Strings::isJson($this->jsonString));
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws \PHPUnit\Framework\ExpectationFailedException
|
||||
* @throws \SebastianBergmann\RecursionContext\InvalidArgumentException
|
||||
*/
|
||||
public function testIsXml()
|
||||
{
|
||||
$this->assertEquals(false, Strings::isXml(''));
|
||||
$this->assertEquals(false, Strings::isXml());
|
||||
$this->assertEquals(false, Strings::isXml($this->jsonString));
|
||||
$this->assertEquals(true, Strings::isXml($this->xmlString));
|
||||
$this->assertEquals(false, Strings::isXml($this->simpleJsonString));
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws \PHPUnit\Framework\ExpectationFailedException
|
||||
* @throws \SebastianBergmann\RecursionContext\InvalidArgumentException
|
||||
*/
|
||||
public function testToArray()
|
||||
{
|
||||
$this->assertEquals($this->simpleJsonArray, Strings::toArray($this->simpleJsonString));
|
||||
$this->assertEquals([], Strings::toArray());
|
||||
$this->assertEquals([], Strings::toArray(''));
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws \PHPUnit\Framework\ExpectationFailedException
|
||||
* @throws \SebastianBergmann\RecursionContext\InvalidArgumentException
|
||||
*/
|
||||
public function testToObject()
|
||||
{
|
||||
$this->assertEquals(true, Strings::toObject($this->simpleJsonString)->json);
|
||||
$this->assertObjectHasAttribute('book', Strings::toObject($this->xmlString));
|
||||
$this->assertEquals(new stdClass(), Strings::toObject());
|
||||
$this->assertEquals(new stdClass(), Strings::toObject(''));
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws \PHPUnit\Framework\ExpectationFailedException
|
||||
* @throws \SebastianBergmann\RecursionContext\InvalidArgumentException
|
||||
*/
|
||||
public function testXmlToArray()
|
||||
{
|
||||
$this->assertArrayHasKey('book', Strings::xmlToArray($this->xmlString));
|
||||
$this->assertObjectHasAttribute('book', Strings::xmlToObject($this->xmlString));
|
||||
}
|
||||
}
|
||||
46
vendor/songshenzong/support/tests/OSTest.php
vendored
Normal file
46
vendor/songshenzong/support/tests/OSTest.php
vendored
Normal file
@@ -0,0 +1,46 @@
|
||||
<?php
|
||||
|
||||
namespace Songshenzong\Support\Test\Core;
|
||||
|
||||
use ReflectionClass;
|
||||
use ReflectionException;
|
||||
use Songshenzong\Support\OS;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* Class OSTest
|
||||
*
|
||||
* @package Songshenzong\Support\Test\Core
|
||||
*/
|
||||
class OSTest extends TestCase
|
||||
{
|
||||
|
||||
/**
|
||||
* @throws ReflectionException
|
||||
*/
|
||||
public function testGetsHomeDirectoryForWindowsUser()
|
||||
{
|
||||
putenv('HOME=');
|
||||
putenv('HOMEDRIVE=C:');
|
||||
putenv('HOMEPATH=\\Users\\Support');
|
||||
$ref = new ReflectionClass(OS::class);
|
||||
$method = $ref->getMethod('getHomeDirectory');
|
||||
$method->setAccessible(true);
|
||||
$this->assertEquals('C:\\Users\\Support', $method->invoke(null));
|
||||
}
|
||||
|
||||
/**
|
||||
* @depends testGetsHomeDirectoryForWindowsUser
|
||||
* @throws ReflectionException
|
||||
*/
|
||||
public function testGetsHomeDirectoryForLinuxUser()
|
||||
{
|
||||
putenv('HOME=/root');
|
||||
putenv('HOMEDRIVE=');
|
||||
putenv('HOMEPATH=');
|
||||
$ref = new ReflectionClass(OS::class);
|
||||
$method = $ref->getMethod('getHomeDirectory');
|
||||
$method->setAccessible(true);
|
||||
$this->assertEquals('/root', $method->invoke(null));
|
||||
}
|
||||
}
|
||||
22
vendor/songshenzong/support/tests/TimeTest.php
vendored
Normal file
22
vendor/songshenzong/support/tests/TimeTest.php
vendored
Normal file
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
namespace Songshenzong\Support\Test\Core;
|
||||
|
||||
use Songshenzong\Support\Time;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class TimeTest extends TestCase
|
||||
{
|
||||
public function testDates()
|
||||
{
|
||||
$expect = [
|
||||
'2019-09-10',
|
||||
'2019-09-11',
|
||||
'2019-09-12',
|
||||
];
|
||||
|
||||
self::assertEquals($expect, Time::dates('2019-09-10', '2019-09-12'));
|
||||
|
||||
self::assertEquals($expect, Time::dates(strtotime('2019-09-10'), strtotime('2019-09-12')));
|
||||
}
|
||||
}
|
||||
11
vendor/songshenzong/support/tests/bootstrap.php
vendored
Normal file
11
vendor/songshenzong/support/tests/bootstrap.php
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
error_reporting(E_ALL);
|
||||
ini_set('display_errors', '1');
|
||||
|
||||
if (!ini_get('date.timezone')) {
|
||||
date_default_timezone_set('GMT');
|
||||
}
|
||||
|
||||
$loader = require dirname(__DIR__) . '/vendor/autoload.php';
|
||||
$loader->add('Songshenzong\\Support\\Test\\', __DIR__);
|
||||
Reference in New Issue
Block a user