ResultTest.php 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. <?php
  2. use Dotenv\Regex\Error;
  3. use Dotenv\Regex\Success;
  4. use PHPUnit\Framework\TestCase;
  5. class ResultTest extends TestCase
  6. {
  7. public function testSuccessValue()
  8. {
  9. $this->assertTrue(Success::create('foo')->error()->isEmpty());
  10. $this->assertTrue(Success::create('foo')->success()->isDefined());
  11. $this->assertEquals('foo', Success::create('foo')->getSuccess());
  12. }
  13. public function testSuccessMapping()
  14. {
  15. $r = Success::create('foo')
  16. ->mapSuccess('strtoupper')
  17. ->mapError('ucfirst');
  18. $this->assertEquals('FOO', $r->getSuccess());
  19. }
  20. /**
  21. * @expectedException \RuntimeException
  22. * @expectedExceptionMessage None has no value.
  23. */
  24. public function testSuccessFail()
  25. {
  26. Success::create('foo')->getError();
  27. }
  28. public function testErrorValue()
  29. {
  30. $this->assertTrue(Error::create('foo')->error()->isDefined());
  31. $this->assertTrue(Error::create('foo')->success()->isEmpty());
  32. $this->assertEquals('foo', Error::create('foo')->getError());
  33. }
  34. public function testErrorMapping()
  35. {
  36. $r = Error::create('foo')
  37. ->mapSuccess('strtoupper')
  38. ->mapError('ucfirst');
  39. $this->assertEquals('Foo', $r->getError());
  40. }
  41. /**
  42. * @expectedException \RuntimeException
  43. * @expectedExceptionMessage None has no value.
  44. */
  45. public function testErrorFail()
  46. {
  47. Error::create('foo')->getSuccess();
  48. }
  49. }