-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
Feature/tests
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,11 +7,11 @@ on: | |
|
||
jobs: | ||
testsuite: | ||
runs-on: ubuntu-18.04 | ||
runs-on: ubuntu-22.04 | ||
strategy: | ||
fail-fast: false | ||
matrix: | ||
php-version: ['7.2', '7.3', '7.4', '8.0'] | ||
php-version: ['7.4', '8.0', '8.1', '8.2', '8.3'] | ||
db-type: [sqlite, mysql, pgsql] | ||
prefer-lowest: [''] | ||
|
||
|
@@ -66,7 +66,7 @@ jobs: | |
if [[ ${{ matrix.db-type }} == 'mysql' ]]; then export DB_URL='mysql://root:[email protected]/cakephp'; fi | ||
if [[ ${{ matrix.db-type }} == 'pgsql' ]]; then export DB_URL='postgres://postgres:[email protected]/postgres'; fi | ||
if [[ ${{ matrix.php-version }} == '7.4' ]]; then | ||
export CODECOVERAGE=1 && vendor/bin/phpunit --verbose --coverage-clover=coverage.xml | ||
export CODECOVERAGE=1 && vendor/bin/phpunit --coverage-clover=coverage.xml | ||
else | ||
vendor/bin/phpunit | ||
fi | ||
|
@@ -77,7 +77,7 @@ jobs: | |
|
||
cs-stan: | ||
name: Coding Standard & Static Analysis | ||
runs-on: ubuntu-18.04 | ||
runs-on: ubuntu-22.04 | ||
|
||
steps: | ||
- uses: actions/checkout@v2 | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,3 +6,4 @@ | |
/config/Migrations/schema-dump-default.lock | ||
/vendor/ | ||
/.idea/ | ||
/.phpunit.cache |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,22 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<phpunit | ||
colors="true" | ||
processIsolation="false" | ||
stopOnFailure="false" | ||
bootstrap="tests/bootstrap.php" | ||
> | ||
<php> | ||
<ini name="memory_limit" value="-1"/> | ||
<ini name="apc.enable_cli" value="1"/> | ||
</php> | ||
|
||
<!-- Add any additional test suites you want to run here --> | ||
<testsuites> | ||
<testsuite name="CakeDC/Money"> | ||
<directory>tests/TestCase/</directory> | ||
</testsuite> | ||
</testsuites> | ||
|
||
<!-- Setup a listener for fixtures --> | ||
<listeners> | ||
<listener class="Cake\TestSuite\Fixture\FixtureInjector"> | ||
<arguments> | ||
<object class="Cake\TestSuite\Fixture\FixtureManager"/> | ||
</arguments> | ||
</listener> | ||
</listeners> | ||
|
||
<filter> | ||
<whitelist> | ||
<directory suffix=".php">src/</directory> | ||
</whitelist> | ||
</filter> | ||
|
||
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" colors="true" processIsolation="false" stopOnFailure="false" bootstrap="tests/bootstrap.php" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd"> | ||
<coverage> | ||
<include> | ||
<directory suffix=".php">src/</directory> | ||
</include> | ||
</coverage> | ||
<php> | ||
<ini name="memory_limit" value="-1"/> | ||
<ini name="apc.enable_cli" value="1"/> | ||
</php> | ||
<!-- Add any additional test suites you want to run here --> | ||
<testsuites> | ||
<testsuite name="CakeDC/Money"> | ||
<directory>tests/TestCase/</directory> | ||
</testsuite> | ||
</testsuites> | ||
<!-- Setup a listener for fixtures --> | ||
<extensions> | ||
<extension class="\Cake\TestSuite\Fixture\PHPUnitExtension"/> | ||
</extensions> | ||
</phpunit> |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -49,6 +49,8 @@ public function __construct(MoneyPHP $money) | |
*/ | ||
public function __call($name, $arguments) | ||
Check failure on line 50 in src/Money.php GitHub Actions / Coding Standard & Static Analysis
Check failure on line 50 in src/Money.php GitHub Actions / Coding Standard & Static Analysis
Check failure on line 50 in src/Money.php GitHub Actions / Coding Standard & Static Analysis
Check failure on line 50 in src/Money.php GitHub Actions / Coding Standard & Static Analysis
Check failure on line 50 in src/Money.php GitHub Actions / Coding Standard & Static Analysis
Check failure on line 50 in src/Money.php GitHub Actions / Coding Standard & Static Analysis
Check failure on line 50 in src/Money.php GitHub Actions / Coding Standard & Static Analysis
Check failure on line 50 in src/Money.php GitHub Actions / Coding Standard & Static Analysis
|
||
{ | ||
$arguments = self::processArguments($arguments); | ||
|
||
return call_user_func_array([$this->_money, $name], $arguments); | ||
} | ||
|
||
|
@@ -59,6 +61,8 @@ public function __call($name, $arguments) | |
*/ | ||
public static function __callStatic($name, $arguments) | ||
Check failure on line 62 in src/Money.php GitHub Actions / Coding Standard & Static Analysis
Check failure on line 62 in src/Money.php GitHub Actions / Coding Standard & Static Analysis
Check failure on line 62 in src/Money.php GitHub Actions / Coding Standard & Static Analysis
Check failure on line 62 in src/Money.php GitHub Actions / Coding Standard & Static Analysis
Check failure on line 62 in src/Money.php GitHub Actions / Coding Standard & Static Analysis
Check failure on line 62 in src/Money.php GitHub Actions / Coding Standard & Static Analysis
Check failure on line 62 in src/Money.php GitHub Actions / Coding Standard & Static Analysis
Check failure on line 62 in src/Money.php GitHub Actions / Coding Standard & Static Analysis
|
||
{ | ||
$arguments = self::processArguments($arguments); | ||
|
||
return new self(forward_static_call_array([MoneyPHP::class, $name], $arguments)); | ||
} | ||
|
||
|
@@ -69,4 +73,19 @@ public function __toString(): string | |
{ | ||
return MoneyUtil::format($this); | ||
} | ||
|
||
/** | ||
* @param array $arguments | ||
* @return array | ||
*/ | ||
protected static function processArguments($arguments = []) | ||
{ | ||
for ($i=0; $i < count($arguments); $i++) { | ||
if ($arguments[$i] instanceof Money) { | ||
$arguments[$i] = $arguments[$i]->getMoney(); | ||
} | ||
} | ||
|
||
return $arguments; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
namespace CakeDC\Money\Test\TestCase\Utility; | ||
|
||
use Cake\Core\Configure; | ||
use Cake\TestSuite\TestCase; | ||
use CakeDC\Money\Database\Type\MoneyType; | ||
use CakeDC\Money\Utility\MoneyUtil; | ||
use Exception; | ||
use PDO; | ||
use RuntimeException; | ||
|
||
/** | ||
* CakeDC\Money\Database\Type\MoneyTypeTest Test Case | ||
*/ | ||
class MoneyTypeTest extends TestCase | ||
{ | ||
/** | ||
* setUp method | ||
* | ||
* @return void | ||
*/ | ||
public function setUp(): void | ||
{ | ||
$this->moneyType = new MoneyType(); | ||
$this->driver = $this->getMockBuilder('Cake\Database\Driver')->getMock(); | ||
parent::setUp(); | ||
} | ||
|
||
/** | ||
* tearDown method | ||
* | ||
* @return void | ||
*/ | ||
public function tearDown(): void | ||
{ | ||
parent::tearDown(); | ||
} | ||
|
||
public function testToPhp() | ||
{ | ||
$this->assertNull($this->moneyType->toPHP(null, $this->driver)); | ||
$this->assertInstanceOf(\CakeDC\Money\Money::class, $this->moneyType->toPHP(100, $this->driver)); | ||
} | ||
|
||
public function testMarshal() | ||
{ | ||
$this->assertNull($this->moneyType->marshal(null)); | ||
$this->assertInstanceOf(\CakeDC\Money\Money::class, $this->moneyType->marshal(100)); | ||
} | ||
|
||
public function testToDatabase() | ||
{ | ||
$this->assertNull($this->moneyType->toDatabase(null, $this->driver)); | ||
$this->assertEquals('10000', $this->moneyType->toDatabase(MoneyUtil::money(100), $this->driver)); | ||
} | ||
|
||
public function testToDatabaseInvalidArgument() | ||
{ | ||
$this->expectException(\InvalidArgumentException::class); | ||
$this->moneyType->toDatabase(100, $this->driver); | ||
} | ||
|
||
public function testToStatement() | ||
{ | ||
$this->assertEquals(PDO::PARAM_NULL, $this->moneyType->toStatement(null, $this->driver)); | ||
$this->assertEquals(PDO::PARAM_INT, $this->moneyType->toStatement(100, $this->driver)); | ||
} | ||
|
||
|
||
} |