PageRenderTime 43ms CodeModel.GetById 17ms RepoModel.GetById 1ms app.codeStats 0ms

/tests/ContainerTest.php

https://gitlab.com/MotoSport/humbug
PHP | 124 lines | 97 code | 17 blank | 10 comment | 0 complexity | 4240ac2ff346f3684e3d5f3addb0d2cf MD5 | raw file
  1. <?php
  2. /**
  3. * Humbug
  4. *
  5. * @category Humbug
  6. * @package Humbug
  7. * @copyright Copyright (c) 2015 Pádraic Brady (http://blog.astrumfutura.com)
  8. * @license https://github.com/padraic/humbug/blob/master/LICENSE New BSD License
  9. *
  10. * @author rafal.wartalski@gmail.com
  11. */
  12. namespace Humbug\Test;
  13. use Humbug\Container;
  14. use Mockery as m;
  15. use Symfony\Component\Finder\Finder;
  16. class ContainerTest extends \PHPUnit_Framework_TestCase
  17. {
  18. private $container;
  19. public function setup()
  20. {
  21. $this->container = new Container(['timeout'=>10]);
  22. }
  23. public function testShouldHaveAdapterOptionsAfterCreate()
  24. {
  25. $input = [
  26. 'options' => 'adapterOpt1 adapterOpt2'
  27. ];
  28. $container = new Container($input);
  29. $this->assertSame(['adapterOpt1', 'adapterOpt2'], $container->getAdapterOptions());
  30. }
  31. public function testGetShouldReturnInputOption()
  32. {
  33. $input = [
  34. 'options' => 'adapterOpt1 adapterOpt2',
  35. 'test' => 'test-option'
  36. ];
  37. $container = new Container($input);
  38. $this->assertSame('test-option', $container->get('test'));
  39. }
  40. public function testGetShouldRiseExceptionForUnknownOption()
  41. {
  42. $input = [
  43. 'options' => null
  44. ];
  45. $this->setExpectedException('\InvalidArgumentException');
  46. $container = new Container($input);
  47. $container->get('invalid-option');
  48. }
  49. public function testSetRunDirectory()
  50. {
  51. $result = $this->container->setTestRunDirectory('/tests/');
  52. $this->assertEquals('/tests', $this->container->getTestRunDirectory());
  53. $this->assertSame($this->container, $result);
  54. }
  55. public function testSetBaseDirectory()
  56. {
  57. $result = $this->container->setBaseDirectory('/test/');
  58. $this->assertEquals('/test', $this->container->getBaseDirectory());
  59. $this->assertSame($this->container, $result);
  60. }
  61. public function testSetSrcList()
  62. {
  63. $list = new \stdClass;
  64. $list->foo = 'bar';
  65. $result = $this->container->setSourceList($list);
  66. $this->assertEquals('bar', $this->container->getSourceList()->foo);
  67. $this->assertSame($this->container, $result);
  68. }
  69. public function testsetTempDirectory()
  70. {
  71. $tmp = sys_get_temp_dir();
  72. $result = $this->container->setTempDirectory($tmp.'/');
  73. $this->assertEquals($tmp, $this->container->getTempDirectory());
  74. $this->assertSame($this->container, $result);
  75. }
  76. public function testsetTempDirectoryThrowsExceptionOnUnwriteableParam()
  77. {
  78. $this->setExpectedException('Humbug\\Exception\\InvalidArgumentException');
  79. $result = $this->container->setTempDirectory('/really/does/not/exist');
  80. }
  81. public function testSetPrimaryTimeout()
  82. {
  83. $this->assertEquals(10, $this->container->getTimeout());
  84. $result = $this->container->setTimeout(20);
  85. $this->assertEquals(20, $this->container->getTimeout());
  86. $this->assertSame($this->container, $result);
  87. }
  88. public function testSetBootstrap()
  89. {
  90. $tmp = tempnam(sys_get_temp_dir(), uniqid());
  91. $this->container->setBootstrap($tmp);
  92. $this->assertEquals($tmp, $this->container->getBootstrap());
  93. @unlink($tmp);
  94. }
  95. public function testGettingMutableFiles()
  96. {
  97. $expected = ['/mutate/me.php'];
  98. $generator = m::mock('Humbug\\Generator');
  99. $finder = m::mock('Symfony\\Component\\Finder\\Finder');
  100. $generator->shouldReceive('generate')->with($finder)->andReturn(null);
  101. $generator->shouldReceive('getMutables')->andReturn($expected);
  102. $result = $this->container->setGenerator($generator);
  103. $this->assertSame($this->container, $result);
  104. $result2 = $this->container->getMutableFiles($finder);
  105. $this->assertSame($expected, $result2);
  106. }
  107. }