GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

PetkoparaFormGeneratorTest::generateForm()   B
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 36
Code Lines 27

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 1 Features 0
Metric Value
dl 0
loc 36
rs 8.8571
c 1
b 1
f 0
cc 1
eloc 27
nc 1
nop 1
1
<?php
2
3
/*
4
 * This file is part of the CrudGeneratorBundle
5
 *
6
 * It is based/extended from SensioGeneratorBundle
7
 *
8
 * (c) Petko Petkov <[email protected]>
9
 *
10
 * For the full copyright and license information, please view the LICENSE
11
 * file that was distributed with this source code.
12
 */
13
14
namespace Petkopara\CrudGeneratorBundle\Tests\Generator;
15
16
use Doctrine\ORM\Mapping\ClassMetadataInfo;
17
use Petkopara\CrudGeneratorBundle\Generator\PetkoparaFormGenerator;
18
use Sensio\Bundle\GeneratorBundle\Tests\Generator\GeneratorTest;
19
20
class PetkoparaFormGeneratorTest extends GeneratorTest
21
{
22
23 View Code Duplication
    public function testGenerate()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
24
    {
25
        $this->generateForm(false);
26
        $this->assertTrue(file_exists($this->tmpDir . '/Form/PostType.php'));
27
        $content = file_get_contents($this->tmpDir . '/Form/PostType.php');
28
        $this->assertContains('->add(\'title\')', $content);
29
        $this->assertContains('->add(\'createdAt\')', $content);
30
        $this->assertContains('->add(\'publishedAt\')', $content);
31
        $this->assertContains('->add(\'updatedAt\')', $content);
32
        $this->assertContains('->add(\'parent\')', $content);
33
        $this->assertContains("'class' => 'FooBundle\Entity\Parent'", $content);
34
        $this->assertContains("'choice_label' => 'name'", $content);
35
        $this->assertContains('class PostType extends AbstractType', $content);
36
        $this->assertContains("'data_class' => 'Foo\BarBundle\Entity\Post'", $content);
37
        if (!method_exists('Symfony\Component\Form\AbstractType', 'getBlockPrefix')) {
38
            $this->assertContains('getName', $content);
39
            $this->assertContains("'foo_barbundle_post'", $content);
40
        } else {
41
            $this->assertNotContains('getName', $content);
42
            $this->assertNotContains("'foo_barbundle_post'", $content);
43
        }
44
    }
45
46
    /**
47
     * @param boolean $overwrite
48
     */
49
    private function generateForm($overwrite)
50
    {
51
52
        $guesser = $this->getMockBuilder('Petkopara\CrudGeneratorBundle\Generator\Guesser\MetadataGuesser')
53
                ->setMethods(array('guessChoiceLabelFromClass'))
54
                ->disableOriginalConstructor()
55
                ->getMock();
56
        $guesser->expects($this->any())->method('guessChoiceLabelFromClass')->will($this->returnValue('name'));
57
58
        $generator = new PetkoparaFormGenerator($guesser);
59
        $generator->setSkeletonDirs(array(__DIR__ . '/../../Resources/skeleton'));
60
61
        $bundle = $this->getMockBuilder('Symfony\Component\HttpKernel\Bundle\BundleInterface')->getMock();
62
        $bundle->expects($this->any())->method('getPath')->will($this->returnValue($this->tmpDir));
63
        $bundle->expects($this->any())->method('getNamespace')->will($this->returnValue('Foo\BarBundle'));
64
65
        $metadata = $this->getMockBuilder('Doctrine\ORM\Mapping\ClassMetadataInfo')->disableOriginalConstructor()->getMock();
66
        $metadata->identifier = array('id');
67
        $metadata->fieldMappings = array(
68
            'title' => array('type' => 'string'),
69
            'createdAt' => array('type' => 'date'),
70
            'publishedAt' => array('type' => 'time'),
71
            'updatedAt' => array('type' => 'datetime'),
72
            'parent' => array('type' => ClassMetadataInfo::MANY_TO_ONE, 'isOwningSide'=> true ,'targetEntity' => 'FooBundle\Entity\Parent'),
73
        );
74
        $metadata->fieldNames = array(
75
            'title' => 'title',
76
            'createdAt' => 'createdAt',
77
            'publishedAt' => 'publishedAt',
78
            'updatedAt' => 'updatedAt',
79
            'parent' => 'parent',
80
        );
81
        $metadata->associationMappings = $metadata->fieldMappings;
82
83
        $generator->generate($bundle, 'Post', $metadata, $overwrite);
84
    }
85
86
}
87