Exemplo n.º 1
0
 public function testAddErrorsArray()
 {
     MockTest::inject($this->validatorFactory, 'errorArray', ['anyKey' => 'initState']);
     $errors = ['anyKey2' => 'anyErrors'];
     MockTest::callMockMethod($this->validatorFactory, 'addErrors', [$errors]);
     $this->assertEquals(\PHPUnit_Framework_Assert::readAttribute($this->validatorFactory, 'errorArray'), ['anyKey' => 'initState', 'anyKey2' => 'anyErrors']);
 }
Exemplo n.º 2
0
 public function testLoadHttp()
 {
     MockTest::inject($this->_load, 'conf', ['conf' => ['tmp' => ['router' => MockTest::mockFileSystem([''])]]]);
     MockTest::inject($this->_load, 'routerYaml', MockTest::mockFile('router.yml'));
     $this->_load->loadHttp();
     $this->assertInstanceOf('App\\Resource\\Http', \PHPUnit_Framework_Assert::readAttribute($this->_load, 'http'));
 }
Exemplo n.º 3
0
 public function testJoin()
 {
     $stub = \Mockery::mock('alias:\\Doctrine\\ORM\\QueryBuilder');
     $stub->shouldReceive('join')->andReturnSelf()->once();
     $this->_queryBuilder = new QueryBuilder($this->getMockIQueryController($stub));
     MockTest::callMockMethod($this->_queryBuilder, 'join', ['column']);
 }
Exemplo n.º 4
0
 public function test__call()
 {
     $stub = \Mockery::mock('SwiftMessage');
     $stub->shouldReceive('setSubject');
     MockTest::inject($this->mail, 'swiftMessage', $stub);
     $this->mail->setSubject();
 }
Exemplo n.º 5
0
 private function dirChmod($mode)
 {
     $dir = MockTest::mockDir('anyDir');
     chmod($dir, $mode);
     MockTest::mockConf('logFileDir', $dir);
     MockTest::mockConf('createLogFile', true);
 }
Exemplo n.º 6
0
 public function testGetAdminExtensionsRouteYaml()
 {
     $structure = ['Menu' => ['router.yml' => '', 'conf.yml' => ''], 'Post' => ['router.yml' => '', 'conf.yml' => ''], 'Page' => ['conf.yml' => '']];
     $this->_adminExtension = new AdminExtension(MockTest::mockFileSystem($structure));
     MockTest::inject($this->_adminExtension, 'extensionsArray', ['Menu', 'Page', 'Post']);
     $this->assertEquals(['vfs://mock/Menu/router.yml', 'vfs://mock/Post/router.yml'], $this->_adminExtension->getAdminExtensionsRouteYaml());
 }
Exemplo n.º 7
0
 public function testSetBreadcrumbsArray()
 {
     $this->mockCategoryList(['anyCategory']);
     MockTest::callMockMethod($this->_categoryBc, 'setBreadcrumbsArray');
     $breadcrumbsArray = \PHPUnit_Framework_Assert::readAttribute($this->_categoryBc, 'breadcrumbsArray');
     $this->assertEquals(['anyCategory'], $breadcrumbsArray);
 }
Exemplo n.º 8
0
 public function testCreateLogFile()
 {
     $logFileDir = dirname(__DIR__) . '/logs';
     MockTest::mockConf('createLogFile', true);
     MockTest::mockConf('logFileDir', $logFileDir);
     $file = "{$logFileDir}/{$this->logFileArray[0]['fileName']}";
     $this->assertTrue(file_exists($file));
 }
Exemplo n.º 9
0
 public function testAliasExistsInDB()
 {
     $alias = 'new-post';
     MockDoctrine::getRepositoryResult([$alias]);
     $this->_alias = new Alias(new \Entity\Posts());
     $aliasNotExistsInDB = MockTest::callMockMethod($this->_alias, 'isAliasNotExistsInDB', [$alias]);
     $this->assertFalse($aliasNotExistsInDB);
 }
Exemplo n.º 10
0
 public function testCatchException()
 {
     $stub = \Mockery::mock('Load');
     $stub->shouldReceive('getExceptionHandler')->once()->andReturnSelf();
     $stub->shouldReceive('catchException')->once();
     MockTest::inject($this->app, 'load', $stub);
     $this->app->catchException(null);
 }
Exemplo n.º 11
0
 /**
  * @expectedException \Ignaszak\Registry\RegistryException
  */
 public function testCantSave()
 {
     $dir = MockTest::mockDir('tmpPath');
     chmod($dir, 00);
     Conf::setTmpPath($dir);
     $stub = $this->getMock('AnyClass');
     $this->fileRegistry->set('anyName', $stub);
 }
Exemplo n.º 12
0
 public function testDataExistsInDatabaseWithException()
 {
     $stub = $this->mockQuery(['value']);
     $stub->shouldReceive('query')->once();
     MockTest::inject($this->uniqueValidator, 'query', $stub);
     $result = MockTest::callMockMethod($this->uniqueValidator, 'dataNotExistInDatabase', ['column', 'value', ['exception']]);
     $this->assertFalse($result);
 }
Exemplo n.º 13
0
 public function testSetLimit()
 {
     $em = \Mockery::mock('EntityManager');
     $em->shouldReceive('setMaxResults')->once();
     MockTest::inject($this->_queryController, 'query', $em);
     $anyLimit = 1;
     $this->_queryController->limit($anyLimit);
     MockTest::callMockMethod($this->_queryController, 'setLimit');
 }
Exemplo n.º 14
0
 public function testAddBreadcrumb()
 {
     $arg = ['anyTitle', 'AnyLink'];
     $addBreadcrumb = MockTest::callMockMethod($this->ibc, 'addBreadcrumb', $arg);
     $this->assertInstanceOf('stdClass', $addBreadcrumb);
     $this->assertEquals('anyTitle', $addBreadcrumb->title);
     $this->assertEquals('AnyLink', $addBreadcrumb->link);
     $this->assertEquals('', $addBreadcrumb->active);
 }
Exemplo n.º 15
0
 public function testAddActiveClass()
 {
     $object = new \stdClass();
     $object->link = 'anyLink';
     $breadcrumbs = ['', $object];
     $addActiveClass = MockTest::callMockMethod($this->bc, 'addActiveClass', [$breadcrumbs]);
     $this->assertEquals('active', $addActiveClass[1]->active);
     $this->assertEquals('', $addActiveClass[1]->link);
 }
Exemplo n.º 16
0
 public function testLoadUserMessageWhenUserIsReporting()
 {
     // Clear counter to call again destructor
     MockTest::injectStatic($this->_controller, 'count');
     MockTest::mockConf('userReporting', E_ALL);
     MockTest::inject($this->_controller, '_logFile', $this->mockLogFile("once"));
     MockTest::inject($this->_controller, '_display', $this->mockDisplay(2));
     $this->_controller->__destruct();
 }
Exemplo n.º 17
0
 public function testIsArrayNotEmpty()
 {
     $args = array('', '', 1, '');
     $isArrayNotEmpty = Mock\MockTest::callMockMethod($this->_controller, 'isArrayNotEmpty', array($args));
     $this->assertEquals(1, $isArrayNotEmpty);
     $args = array('', '', 0, '');
     $isArrayNotEmpty = Mock\MockTest::callMockMethod($this->_controller, 'isArrayNotEmpty', array($args));
     $this->assertEquals(0, $isArrayNotEmpty);
 }
Exemplo n.º 18
0
 public function testCutString()
 {
     $string = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam ultrices enim turpis, in auctor massa dictum sit amet. In hac habitasse platea dictumst.";
     $cutString = MockTest::callMockMethod($this->_handler, 'cutString', array($string));
     $this->assertEquals("Lorem ipsum dolor sit amet, consectetur ...", $cutString);
     $string = "Lorem ipsum dolor sit amet, consectetur";
     $cutString = MockTest::callMockMethod($this->_handler, 'cutString', array($string));
     $this->assertEquals("Lorem ipsum dolor sit amet, consectetur", $cutString);
 }
Exemplo n.º 19
0
 public static function run(array $data = null)
 {
     $_conf = RegistryFactory::start('file')->register('Conf\\Conf');
     $array = ['getId' => null, 'getSiteTitle' => '', 'getAdminEmail' => '', 'getViewLimit' => null, 'getDateFormat' => '', 'getBaseUrl' => '', 'getRequestUri' => '', 'getTheme' => ''];
     if (!is_null($data)) {
         foreach ($data as $key => $value) {
             $array[$key] = $value;
         }
     }
     MockTest::inject($_conf, 'optionsArray', $array);
 }
Exemplo n.º 20
0
 public function testRunOnDevAndUserMode()
 {
     $stub = $this->getMockBuilder('Ignaszak\\Exception\\Handler\\ErrorHandler')->getMock();
     $stub->expects($this->once())->method('setErrorHandler');
     $stub->expects($this->once())->method('setShutdownHandler');
     MockTest::inject($this->start, '_errorHandler', $stub);
     $stub = $this->getMockBuilder('Ignaszak\\Exception\\Handler\\ExceptionHandler')->getMock();
     $stub->expects($this->once())->method('setExceptionHandler');
     MockTest::inject($this->start, '_exceptionHandler', $stub);
     $this->start->display = 'user';
     $this->start->run();
 }
Exemplo n.º 21
0
    public function testActive()
    {
        RegistryFactory::start()->set('http', $this->mockHttp('Page', 'admin-post-add'));
        $structure = ['Post' => ['conf.yml' => ''], 'Page' => ['conf.yml' => <<<EOT
menu:
    - {title: Add new post, url: admin-post-add, tokens: {action: add}}
    - {title: Add new post 2, url: admin-post-add-2, tokens: {action: add-2}}
EOT
]];
        $this->admin = new Admin($this->mockAdminExtension(MockTest::mockFileSystem($structure), ['Post', 'Page']), new Yaml());
        $this->assertEquals([0 => ['active' => false], 1 => ['active' => true, 'menu' => [0 => ['active' => true, 'title' => 'Add new post', 'url' => 'generatedUrl'], 1 => ['active' => false, 'title' => 'Add new post 2', 'url' => 'generatedUrl']]]], $this->admin->getAdminMenu());
    }
Exemplo n.º 22
0
 /**
  * Clear mock entity from \Conf\DB\DBDoctrine
  */
 public static function clear()
 {
     MockTest::injectStatic('Conf\\DB\\DBDoctrine', 'em');
 }
Exemplo n.º 23
0
 private function getErrorTypeByNumber(int $errorType) : string
 {
     return MockTest::callMockMethod($this->_errorHandler, 'getErrorTypeByNumber', array($errorType));
 }
Exemplo n.º 24
0
 /**
  * @expectedException \RuntimeException
  */
 public function testGetFormGroupWithNoExistingGroupForm()
 {
     $this->_form->createForm('noExistingGroup-action');
     MockTest::callMockMethod($this->_form, 'getFormGroup');
 }
Exemplo n.º 25
0
 public function testBegin()
 {
     MockTest::inject($this->_fileContent, 'offset', 10);
     MockTest::inject($this->_fileContent, 'line', 66);
     $this->assertEquals(56, MockTest::callMockMethod($this->_fileContent, 'getBegin'));
 }
Exemplo n.º 26
0
 public function testGetFormActionFromGroup()
 {
     $this->mockGroup('anyGroupWithoutAction');
     $action = MockTest::callMockMethod($this->group, 'getFormAction');
     $this->assertEquals('anyGroupWithoutAction', $action);
 }
Exemplo n.º 27
0
 private function injectMockTransport()
 {
     MockTest::inject($this->_mailTransport, 'transportClassName', '\\Test\\Model\\Mail\\MockAnySwiftTransport');
 }
Exemplo n.º 28
0
 public function testReadFromYaml()
 {
     $yamlFile = MockTest::mockFile('anyYamlFile.yml', 0644, 'any: content');
     $this->assertEquals(['any' => 'content'], $this->yaml->parse($yamlFile));
 }
Exemplo n.º 29
0
 public function testGetRouteArray()
 {
     $stub = $this->getMockBuilder('Ignaszak\\Router\\Matcher\\Converter')->disableOriginalConstructor()->getMock();
     $stub->expects($this->once())->method('convert')->willReturn([]);
     MockTest::inject($this->route, 'converter', $stub);
     $this->route->getRouteArray();
 }
Exemplo n.º 30
0
 public function testGetRouteArray()
 {
     // Read from converter
     $this->cache = new Cache($this->mockIRoute('anyChecksum', ['anyRouteArray']));
     $tmpDir = MockTest::mockDir('anyDir');
     MockTest::inject($this->cache, 'tmpDir', $tmpDir);
     $this->assertEquals(['anyRouteArray'], $this->cache->getRouteArray());
     // Read from cache
     MockTest::inject($this->cache, 'route', $this->mockIRoute('anyChecksum', ['anyRouteArray']));
     $this->assertEquals(['anyRouteArray'], $this->cache->getRouteArray());
 }