0
votes

I can't solve the problem with testing in PHPUnit. This is my code, and there's sommething wrong with it. This is the Annual percentage rate calculation ( https://en.wikipedia.org/wiki/Annual_percentage_rate ).

In cmd:

    C:\Users\Shambler\Downloads\test-taeg-senior\test-taeg>phpunit
PHP Warning:  Module 'oci8' already loaded in Unknown on line 0

Warning: Module 'oci8' already loaded in Unknown on line 0
PHPUnit 3.7.21 by Sebastian Bergmann.

Configuration read from C:\Users\Shambler\Downloads\test-taeg-senior\test-taeg\phpunit.xml



Time: 74 ms, Memory: 2.00MB

No tests executed!

C:\Users\Shambler\Downloads\test-taeg-senior\test-taeg>

Don't think about Oracle module, it's another story. I ran "phpunit" after "composer install".

project/tests/test-general.php:

    <?php

use MotorK\{ Rate, Tae, Taeg };

class TestTaeg extends \PHPUnit\Framework\TestCase {

    /**
     * Example from http://www.calcolatoremutui.it/tan-e-taeg/
     */
    public function test_tae() {
        $obj = Tae::init( 5, 12 );

        $this->assertEquals( 5.116, round( $obj->calculate(), 3 ) );

        $this->expectOutputString( '5.116 %' );
        echo $obj;
    }

    /**
     * Example from http://www.calcolatoremutui.it/tan-e-taeg/
     */
    public function test_rate() {
        $obj = Rate::init( 100000, 5, 12, 20 );

        $this->assertEquals( 659.96, round( $obj->calculate(), 2 ) );

        $this->expectOutputString( '659.96 €' );
        echo $obj;
    }

    /**
     * Example from http://www.calcolatoremutui.it/tan-e-taeg/
     */
    public function test_taeg() {
        $obj = Taeg::init( 99000, 5, 661.96, 12, 20 );

        $this->assertEquals( 5.281, round( $obj->calculate(), 3 ) );

        $this->expectOutputString( '5.281 %' );
        echo $obj;
    }
}

project/phpunit.xml

<phpunit
bootstrap="tests/bootstrap.php"
backupGlobals="false"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
>
<testsuite name="Internal tests">
    <directory prefix="test-" suffix=".php">./tests/</directory>
</testsuite>
<groups>
    <include>
        <group>default</group>
    </include>
</groups>
<filter>
    <whitelist>
        <directory suffix=".php">./includes/</directory>
    </whitelist>
</filter>

I can't solve it, tried it many times :(

2

2 Answers

3
votes

The suffix (not the prefix) of a test case class' name must be Test. And the sourcecode file's name must match the class name.

In your example, you probably want TaegTest (instead of TestTaeg) declared in TaegTest.php (instead of test-general.php).

Also note that the version of PHPUnit you use has reached its end of life years ago. Read this to get started working with a recent version of PHPUnit.

0
votes

You need to create include folder and under that you need to create MotorK folder and then you should create classes. You should have following directory structure:

test-taeg/includes/MotorK

test-taeg
+
|
+-include
|
++ --MotorK
|
+++ ---Rate.php
|
+++ ---Tae.php
|
+++ ---Taeg.php

MotorK should be your namespace.