tests(service): 添加了base64Wrapper的测试

This commit is contained in:
李东云
2022-12-20 15:08:04 +08:00
parent e004ab402d
commit 69ce66561f
7 changed files with 103 additions and 9 deletions

1
.gitignore vendored
View File

@@ -1 +1,2 @@
vendor/
.phpunit.result.cache

7
.idea/HDK-Core.iml generated
View File

@@ -4,7 +4,7 @@
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/spec" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" packagePrefix="Singularity\HDK\Core\" />
<sourceFolder url="file://$MODULE_DIR$/tests" isTestSource="true" packagePrefix="Singularity\HDK\Test\\Core\" />
<sourceFolder url="file://$MODULE_DIR$/tests" isTestSource="true" packagePrefix="Singularity\HDK\Test\Core\" />
<excludeFolder url="file://$MODULE_DIR$/vendor/sebastian/recursion-context" />
<excludeFolder url="file://$MODULE_DIR$/vendor/sebastian/lines-of-code" />
<excludeFolder url="file://$MODULE_DIR$/vendor/sebastian/type" />
@@ -131,6 +131,11 @@
<excludeFolder url="file://$MODULE_DIR$/vendor/sebastian/code-unit-reverse-lookup" />
<excludeFolder url="file://$MODULE_DIR$/vendor/sebastian/diff" />
<excludeFolder url="file://$MODULE_DIR$/vendor/swoole/ide-helper" />
<excludeFolder url="file://$MODULE_DIR$/vendor/pestphp/pest" />
<excludeFolder url="file://$MODULE_DIR$/vendor/pestphp/pest-plugin" />
<excludeFolder url="file://$MODULE_DIR$/vendor/filp/whoops" />
<excludeFolder url="file://$MODULE_DIR$/vendor/nunomaduro/collision" />
<excludeFolder url="file://$MODULE_DIR$/vendor/facade/ignition-contracts" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />

5
.idea/php.xml generated
View File

@@ -137,6 +137,11 @@
<path value="$PROJECT_DIR$/vendor/sebastian/code-unit-reverse-lookup" />
<path value="$PROJECT_DIR$/vendor/sebastian/diff" />
<path value="$PROJECT_DIR$/vendor/swoole/ide-helper" />
<path value="$PROJECT_DIR$/vendor/pestphp/pest" />
<path value="$PROJECT_DIR$/vendor/pestphp/pest-plugin" />
<path value="$PROJECT_DIR$/vendor/filp/whoops" />
<path value="$PROJECT_DIR$/vendor/nunomaduro/collision" />
<path value="$PROJECT_DIR$/vendor/facade/ignition-contracts" />
</include_path>
</component>
<component name="PhpProjectSharedConfiguration" php_language_level="8.0" />

View File

@@ -1,9 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" bootstrap="vendor/autoload.php" backupGlobals="false" colors="true" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.5/phpunit.xsd">
<coverage/>
<testsuites>
<testsuite name="Example">
<directory>./tests/Example/</directory>
</testsuite>
</testsuites>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" bootstrap="vendor/autoload.php"
colors="true" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.5/phpunit.xsd">
<coverage/>
<testsuites>
<testsuite name="Unit">
<directory>./tests/Unit/</directory>
</testsuite>
</testsuites>
</phpunit>

5
tests/ExampleTest.php Normal file
View File

@@ -0,0 +1,5 @@
<?php
test('example', function () {
expect(true)->toBeTrue();
});

45
tests/Pest.php Normal file
View File

@@ -0,0 +1,45 @@
<?php
/*
|--------------------------------------------------------------------------
| Test Case
|--------------------------------------------------------------------------
|
| The closure you provide to your test functions is always bound to a specific PHPUnit test
| case class. By default, that class is "PHPUnit\Framework\TestCase". Of course, you may
| need to change it using the "uses()" function to bind a different classes or traits.
|
*/
// uses(Tests\TestCase::class)->in('Feature');
/*
|--------------------------------------------------------------------------
| Expectations
|--------------------------------------------------------------------------
|
| When you're writing tests, you often need to check that values meet certain conditions. The
| "expect()" function gives you access to a set of "expectations" methods that you can use
| to assert different things. Of course, you may extend the Expectation API at any time.
|
*/
expect()->extend('toBeOne', function () {
return $this->toBe(1);
});
/*
|--------------------------------------------------------------------------
| Functions
|--------------------------------------------------------------------------
|
| While Pest is very powerful out-of-the-box, you may have some testing code specific to your
| project that you don't want to repeat in every file. Here you can also expose helpers as
| global functions to help you to reduce the number of lines of code in your test files.
|
*/
function something()
{
// ..
}

View File

@@ -0,0 +1,32 @@
<?php
/**
* Base64WrapperTest.php@HDK-Core
*
* @author 李东云 <Dongyun.Li@LuxCreo.Ai>
* Powered by PhpStorm
* Created on 2022/12/20
*/
namespace Singularity\HDK\Test\Core\Unit;
use Singularity\HDK\Core\Service\Base64Wrapper;
use PHPUnit\Framework\TestCase;
it('assertions base64 wrapper ENCODE', function(string $source, string $expected) {
$encoded = (new Base64Wrapper())->encode($source);
expect($expected)->toBe($encoded);
})->with([
['abc==', 'abc'],
['=ccc=', 'ccc'],
['YWJ/+j', 'YWJ_-j']
]);
it('assertions base64 wrapper DECODE', function(string $source, string $expected) {
$decoded = (new Base64Wrapper())->decode($source);
expect($expected)->toBe($decoded);
})->with([
['abc', 'abc'],
['YWJ_-j', 'YWJ/+j']
]);