CalculatorTest.php 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: yguern
  5. * Date: 29/09/2017
  6. * Time: 09:01
  7. */
  8. namespace Cloud\RDexp\Calculator;
  9. class CalculatorTest extends \PHPUnit_Framework_TestCase
  10. {
  11. /**
  12. * @var Calculator $calculator
  13. */
  14. private $calculator;
  15. public function setUp()
  16. {
  17. $this->calculator = new Calculator();
  18. }
  19. /**
  20. * What : try to add non real number 10 + 'test'
  21. * Expected : An exception must be thrown
  22. */
  23. public function testAddNonRealNumber() {
  24. $this->calculator = new Calculator();
  25. try {
  26. $this->calculator->add(10, 'test');
  27. $this->assertFalse(true, "An exception must be thrown");
  28. } catch (\Exception $e) {
  29. $this->assertInstanceOf(CalculatorException::class, $e);
  30. $this->assertEquals("Adding not real numbers", $e->getMessage());
  31. }
  32. }
  33. /**
  34. * What : add to real numbers (10.1 + 42)
  35. * Expected : Returns 52.1
  36. */
  37. public function testAddRealNumber() {
  38. $result = $this->calculator->add(10.1, 42);
  39. $this->assertEquals(52.1, $result);
  40. }
  41. }