LoaderFactoryTest.php 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. <?php
  2. namespace Fgm\ComposerCheck\Tests;
  3. use Fgm\ComposerCheck\LoaderFactory;
  4. /**
  5. * Class LoaderFactoryTest.
  6. *
  7. * @coversDefaultClass \Fgm\ComposerCheck\LoaderFactory
  8. */
  9. class LoaderFactoryTest extends \PHPUnit_Framework_TestCase {
  10. const NS = 'Fgm\\ComposerCheck\\';
  11. /**
  12. * Test the normal construction case.
  13. *
  14. * @covers ::__construct()
  15. * @covers ::validateDirectory()
  16. */
  17. public function testHappyConstructor() {
  18. // This is a Composer project, so it should be installed to run its tests.
  19. $dir = __DIR__ . '/../..';
  20. $factory = new LoaderFactory($dir);
  21. $this->assertInstanceOf(self::NS . 'LoaderFactory', $factory);
  22. }
  23. /**
  24. * Tests constructing on an existing directory with missing composer files.
  25. *
  26. * @covers ::__construct()
  27. * @covers ::validateDirectory()
  28. *
  29. * @expectedException \InvalidArgumentException
  30. */
  31. public function testSadConstructorMissing() {
  32. $dir = __DIR__;
  33. new LoaderFactory($dir);
  34. }
  35. /**
  36. * Tests constructing on a missing directory.
  37. *
  38. * @covers ::__construct()
  39. * @covers ::validateDirectory()
  40. *
  41. * @expectedException \InvalidArgumentException
  42. */
  43. public function testSadConstructorInvalid() {
  44. $dir = '/dev/null/nowhere';
  45. new LoaderFactory($dir);
  46. }
  47. /**
  48. * Testes a successful load for requirements and lock.
  49. *
  50. * @covers ::createLoader()
  51. */
  52. public function testHappyCreateLoader() {
  53. $dir = __DIR__ . '/../..';
  54. $factory = new LoaderFactory($dir);
  55. $loader = $factory->createLoader('requirements');
  56. $this->assertInstanceOf(self::NS . 'RequirementsLoader', $loader);
  57. $loader = $factory->createLoader('lock');
  58. $this->assertInstanceOf(self::NS . 'LockLoader', $loader);
  59. }
  60. /**
  61. * Tests an attempt to load an invalid type of composer file.
  62. *
  63. * @covers ::createLoader()
  64. *
  65. * @expectedException \InvalidArgumentException
  66. */
  67. public function testSadCreateLoader() {
  68. $dir = __DIR__ . '/../..';
  69. $factory = new LoaderFactory($dir);
  70. $factory->createLoader('invalid');
  71. }
  72. }