/class/libraries/vendor/ircmaxell/security-lib/test/Unit/Core/AbstractFactoryTest.php

https://gitlab.com/VoyaTrax/vtCMS2 · PHP · 67 lines · 40 code · 15 blank · 12 comment · 0 complexity · 26c327a59a4024c08b561d0e3f614636 MD5 · raw file

  1. <?php
  2. use SecurityLibTest\Mocks\Factory;
  3. use org\bovigo\vfs\vfsStream;
  4. class Unit_Core_AbstractFactoryTest extends PHPUnit_Framework_TestCase {
  5. protected function setUp() {
  6. $root = vfsStream::setup('SecurityLibTest');
  7. //Setup Folders
  8. $core = vfsStream::newDirectory('Core')->at($root);
  9. $af = vfsStream::newDirectory('AbstractFactory')->at($core);
  10. // Create Files
  11. vfsStream::newFile('test.php')->at($af);
  12. vfsStream::newFile('Some234Foo234Bar98Name.php')->at($af);
  13. vfsStream::newFile('Invalid.csv')->at($af);
  14. vfsStream::newFile('badlocation.php')->at($core);
  15. }
  16. /**
  17. * @covers SecurityLib\AbstractFactory::registerType
  18. */
  19. public function testRegisterType() {
  20. $factory = new Factory;
  21. $factory->registerType('test', 'iteratoraggregate', 'foo', 'ArrayObject', false);
  22. }
  23. /**
  24. * @covers SecurityLib\AbstractFactory::registerType
  25. * @expectedException InvalidArgumentException
  26. */
  27. public function testRegisterTypeFail() {
  28. $factory = new Factory;
  29. $factory->registerType('test', 'iterator', 'foo', 'ArrayObject', false);
  30. }
  31. /**
  32. * @covers SecurityLib\AbstractFactory::registerType
  33. */
  34. public function testRegisterTypeInstantiate() {
  35. $factory = new Factory;
  36. $factory->registerType('test', 'iteratoraggregate', 'foo', 'ArrayObject', true);
  37. }
  38. public function testLoadFiles() {
  39. $dir = vfsStream::url('SecurityLibTest/Core/AbstractFactory');
  40. $result = array();
  41. $callback = function($name, $class) use (&$result) {
  42. $result[$name] = $class;
  43. };
  44. $factory = new Factory();
  45. $factory->loadFiles($dir, 'foo\\', $callback);
  46. $expect = array(
  47. 'test' => 'foo\\test',
  48. 'Some234Foo234Bar98Name' => 'foo\\Some234Foo234Bar98Name'
  49. );
  50. $this->assertEquals($expect, $result);
  51. }
  52. }