diff --git a/.gitignore b/.gitignore index a725465..aa30d8b 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ -vendor/ \ No newline at end of file +vendor/ +.phpunit.result.cache \ No newline at end of file diff --git a/.idea/HDK-Core.iml b/.idea/HDK-Core.iml index 56b900d..67b0141 100644 --- a/.idea/HDK-Core.iml +++ b/.idea/HDK-Core.iml @@ -4,7 +4,7 @@ - + @@ -131,6 +131,11 @@ + + + + + diff --git a/.idea/php.xml b/.idea/php.xml index 966e066..c0eecbe 100644 --- a/.idea/php.xml +++ b/.idea/php.xml @@ -137,6 +137,11 @@ + + + + + diff --git a/phpunit.xml b/phpunit.xml index d747ff4..df1e643 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -1,9 +1,10 @@ - - - - - ./tests/Example/ - - + + + + + ./tests/Unit/ + + diff --git a/tests/ExampleTest.php b/tests/ExampleTest.php new file mode 100644 index 0000000..61cd84c --- /dev/null +++ b/tests/ExampleTest.php @@ -0,0 +1,5 @@ +toBeTrue(); +}); diff --git a/tests/Pest.php b/tests/Pest.php new file mode 100644 index 0000000..5949c61 --- /dev/null +++ b/tests/Pest.php @@ -0,0 +1,45 @@ +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() +{ + // .. +} diff --git a/tests/Unit/Base64WrapperTest.php b/tests/Unit/Base64WrapperTest.php new file mode 100644 index 0000000..09ab878 --- /dev/null +++ b/tests/Unit/Base64WrapperTest.php @@ -0,0 +1,32 @@ + + * 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'] +]);