Skip to content

Commit

Permalink
Switching to PHP 8
Browse files Browse the repository at this point in the history
  • Loading branch information
AndyM84 committed Jan 20, 2021
1 parent ce1ad13 commit 46b8805
Show file tree
Hide file tree
Showing 3 changed files with 108 additions and 114 deletions.
148 changes: 75 additions & 73 deletions Tests/Utilities/ReturnHelperTest.php
Original file line number Diff line number Diff line change
@@ -1,73 +1,75 @@
<?php

namespace Stoic\Utilities\Tests;

use PHPUnit\Framework\TestCase;
use Stoic\Utilities\ReturnHelper;

class ReturnHelperTest extends TestCase {
public function test_MessageHandling() {
$ret = new ReturnHelper();
self::assertEquals(0, count($ret->getMessages()), "ReturnHelper returns the correct number of messages");
self::assertFalse($ret->hasMessages(), "ReturnHelper notes absence of messages correctly");

$ret->addMessage("Testing");
self::assertEquals(1, count($ret->getMessages()), "ReturnHelper returns the correct number of messages");

$ret->addMessages(array(
"Testing2",
"Testing3"
));
self::assertEquals(3, count($ret->getMessages()), "ReturnHelper returns the correct number of messages");
self::assertTrue($ret->hasMessages(), "ReturnHelper notes presence of messages correctly");
self::assertArraySubset(array("Testing", "Testing2", "Testing3"), $ret->getMessages(), true, "ReturnHelper returns the correct messages");

try {
$ret->addMessages([]);
self::assertTrue(false);
} catch (\InvalidArgumentException $ex) {
self::assertEquals("Messages array to ReturnHelper::addMessages() must be array with elements", $ex->getMessage());
}

return;
}

public function test_ResultHandling() {
$ret = new ReturnHelper();
self::assertEquals(0, count($ret->getResults()), "ReturnHelper returns the correct number of results");
self::assertFalse($ret->hasResults(), "ReturnHelper notes absence of results correctly");

$ret->addResult("Testing");
self::assertEquals(1, count($ret->getResults()), "ReturnHelper returns the correct number of results");

$ret->addResults(array(
"Testing2",
"Testing3"
));
self::assertEquals(3, count($ret->getResults()), "ReturnHelper returns the correct number of results");
self::assertTrue($ret->hasResults(), "ReturnHelper notes presence of results correctly");
self::assertArraySubset(array("Testing", "Testing2", "Testing3"), $ret->getResults(), true, "ReturnHelper returns the correct results");

try {
$ret->addResults([]);
self::assertTrue(false);
} catch (\InvalidArgumentException $ex) {
self::assertEquals("Results array to ReturnHelper::addResults() must be array with elements", $ex->getMessage());
}

return;
}

public function test_GoodVsBad() {
$ret = new ReturnHelper();
self::assertTrue($ret->isBad(), "ReturnHelper initializes as STATUS_BAD");

$ret->makeGood();
self::assertTrue($ret->isGood(), "ReturnHelper is made STATUS_GOOD");

$ret->makeBad();
self::assertTrue($ret->isBad(), "ReturnHelper is made STATUS_BAD");

return;
}
}
<?php

namespace Stoic\Utilities\Tests;

use PHPUnit\Framework\TestCase;
use Stoic\Utilities\ReturnHelper;

class ReturnHelperTest extends TestCase {
public function test_MessageHandling() {
$ret = new ReturnHelper();
self::assertEquals(0, count($ret->getMessages()), "ReturnHelper returns the correct number of messages");
self::assertFalse($ret->hasMessages(), "ReturnHelper notes absence of messages correctly");

$ret->addMessage("Testing");
self::assertEquals(1, count($ret->getMessages()), "ReturnHelper returns the correct number of messages");

$ret->addMessages(["Testing2", "Testing3"]);
self::assertEquals(3, count($ret->getMessages()), "ReturnHelper returns the correct number of messages");
self::assertTrue($ret->hasMessages(), "ReturnHelper notes presence of messages correctly");

$messages = $ret->getMessages();
self::assertEquals("Testing", $messages[0], "ReturnHelper returned the correct messages");
self::assertEquals("Testing2", $messages[1], "ReturnHelper returned the correct messages");
self::assertEquals("Testing3", $messages[2], "ReturnHelper returned the correct messages");

try {
$ret->addMessages([]);
self::assertTrue(false);
} catch (\InvalidArgumentException $ex) {
self::assertEquals("Messages array to ReturnHelper::addMessages() must be array with elements", $ex->getMessage());
}

return;
}

public function test_ResultHandling() {
$ret = new ReturnHelper();
self::assertEquals(0, count($ret->getResults()), "ReturnHelper returns the correct number of results");
self::assertFalse($ret->hasResults(), "ReturnHelper notes absence of results correctly");

$ret->addResult("Testing");
self::assertEquals(1, count($ret->getResults()), "ReturnHelper returns the correct number of results");

$ret->addResults(["Testing2", "Testing3"]);
self::assertEquals(3, count($ret->getResults()), "ReturnHelper returns the correct number of results");
self::assertTrue($ret->hasResults(), "ReturnHelper notes presence of results correctly");

$results = $ret->getResults();
self::assertEquals("Testing", $results[0], "ReturnHelper returned the correct messages");
self::assertEquals("Testing2", $results[1], "ReturnHelper returned the correct messages");
self::assertEquals("Testing3", $results[2], "ReturnHelper returned the correct messages");

try {
$ret->addResults([]);
self::assertTrue(false);
} catch (\InvalidArgumentException $ex) {
self::assertEquals("Results array to ReturnHelper::addResults() must be array with elements", $ex->getMessage());
}

return;
}

public function test_GoodVsBad() {
$ret = new ReturnHelper();
self::assertTrue($ret->isBad(), "ReturnHelper initializes as STATUS_BAD");

$ret->makeGood();
self::assertTrue($ret->isGood(), "ReturnHelper is made STATUS_GOOD");

$ret->makeBad();
self::assertTrue($ret->isBad(), "ReturnHelper is made STATUS_BAD");

return;
}
}
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "stoic/stoic",
"description": "Stoic framework Core component",
"version": "1.0.1",
"version": "1.0.2",
"homepage": "https://stoic-framework.com",
"autoload": {
"psr-0": {
Expand All @@ -19,11 +19,11 @@
]
},
"require": {
"php": "^7.0",
"php": ">=7.4",
"psr/log": "^1.0.0"
},
"require-dev": {
"phpunit/phpunit": "^7"
"phpunit/phpunit": "^9"
},
"provide": {
"psr/log-implementation": "1.0.0"
Expand Down
68 changes: 30 additions & 38 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -1,39 +1,31 @@
<?xml version="1.0" encoding="UTF-8"?>

<phpunit
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/4.5/phpunit.xsd"
bootstrap="vendor/autoload.php"
colors="false"
stopOnError="false"
stopOnFailure="false"
stopOnIncomplete="false"
stopOnSkipped="false"
stopOnRisky="false">
<php>
<ini name="error_reporting" value="-1" />
</php>
<testsuites>
<testsuite name="Chain Tests">
<directory suffix="Test.php">./Tests/Chain/</directory>
</testsuite>
<testsuite name="Logger Tests">
<directory suffix="Test.php">./Tests/Log/</directory>
</testsuite>
<testsuite name="Utility Tests">
<directory suffix="Test.php">./Tests/Utilities/</directory>
</testsuite>
</testsuites>
<filter>
<whitelist addUncoveredFilesFromWhitelist="true" processUncoveredFilesFromWhitelist="true">
<directory suffix=".php">./Chain</directory>
<directory suffix=".php">./Log</directory>
<directory suffix=".php">./Utilities</directory>
</whitelist>
</filter>
<logging>
<log type="junit" target="reports/phpunit.xml" />
<log type="coverage-clover" target="coverage/phpunit.xml" />
<log type="coverage-html" target="coverage/" />
</logging>
</phpunit>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd" bootstrap="vendor/autoload.php" colors="false" stopOnError="false" stopOnFailure="false" stopOnIncomplete="false" stopOnSkipped="false" stopOnRisky="false">
<coverage includeUncoveredFiles="true" processUncoveredFiles="true">
<include>
<directory suffix=".php">./Chain</directory>
<directory suffix=".php">./Log</directory>
<directory suffix=".php">./Utilities</directory>
</include>
<report>
<clover outputFile="coverage/phpunit.xml"/>
<html outputDirectory="coverage/"/>
</report>
</coverage>
<php>
<ini name="error_reporting" value="-1"/>
</php>
<testsuites>
<testsuite name="Chain Tests">
<directory suffix="Test.php">./Tests/Chain/</directory>
</testsuite>
<testsuite name="Logger Tests">
<directory suffix="Test.php">./Tests/Log/</directory>
</testsuite>
<testsuite name="Utility Tests">
<directory suffix="Test.php">./Tests/Utilities/</directory>
</testsuite>
</testsuites>
<logging>
<junit outputFile="reports/phpunit.xml"/>
</logging>
</phpunit>

0 comments on commit 46b8805

Please sign in to comment.