PHP Classes

File: test/AdditionTest.php

Recommend this page to a friend!
  Classes of stefan  >  PHP Calculator  >  test/AdditionTest.php  >  Download  
File: test/AdditionTest.php
Role: Class source
Content type: text/plain
Description: Class source
Class: PHP Calculator
Calculate the result of multiple math operations
Author: By
Last change: resolve error ( and sin( in same term
Date: 10 months ago
Size: 1,743 bytes
 

Contents

Class file image Download
<?php declare(strict_types=1);
use
PHPUnit\Framework\TestCase;
    use
Taschenrechner\Classes\Calculator;
    use
Taschenrechner\Classes\Operationen\Addition;
    use
Taschenrechner\Classes\Concatinator;

require_once
"init.php";
require_once(
dirname(__FILE__)."/../vendor/autoload.php");

final class
AdditionTest extends TestCase
{
    private
$operation;
    private
$concatinator;
    private
$calculator;
    private
$stub;
    protected function
setUp(): void
   
{
       
$this->calculator = $this->createMock(Calculator::class);
       
$this->concatinator = $this->createMock(Concatinator::class);
    }
   
    public function
testTerm10Plus5Equals15(): void
   
{
       
$this->operation = new Addition($this->calculator, $this->concatinator);
       
$this->concatinator->method('concatinateArray')->willReturn(array(10,"+",5));
       
       
$this->assertSame("15", $this->operation->findAndCalculateTerm("10+5",(new Init())->operations()));

    }

   
    public function
addTermProvider() {
        return array(
           
"Term 2 plus 20 plus 10" => array(array(2,"+", 20, "+", 10),"2+20+10" ,"22+10"),
           
        );
    }

   
/**
     * @dataProvider addTermProvider
     */
   
public function testTerm($concatinatedValues, $term, $expected)
    {
       
$this->operation = new Addition($this->calculator, $this->concatinator);
       
$this->concatinator->method('concatinateArray')->willReturn($concatinatedValues);
       
       
$this->assertSame($expected, $this->operation->findAndCalculateTerm($term, (new Init())->operations()));

    }

    protected function
tearDown(): void
   
{
       
$this->calculator = NULL;
       
$this->concatinator = NULL;

    }
  
}