Skip to content

Commit

Permalink
zendframework#6288 - cleaning up assertions, using correct assertions…
Browse files Browse the repository at this point in the history
… for counts, reducing code amount
  • Loading branch information
Ocramius authored and dima committed Nov 27, 2014
1 parent 65d8808 commit 1885e1e
Showing 1 changed file with 34 additions and 34 deletions.
68 changes: 34 additions & 34 deletions tests/ZendTest/Code/Generator/ClassGeneratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -537,55 +537,51 @@ public function someFunction()
public function testCanAddConstant()
{
$classGenerator = new ClassGenerator();

$classGenerator->setName('My\Class');
$classGenerator->addConstant('x', 'value');

$this->assertTrue($classGenerator->hasConstant('x'));

$constant = $classGenerator->getConstant('x');
$this->assertTrue($constant instanceof PropertyGenerator);

$this->assertInstanceOf('Zend\Code\Generator\PropertyGenerator', $constant);
$this->assertTrue($constant->isConst());
$this->assertEquals($constant->getDefaultValue()->getValue(), 'value');

}

/**
* @group 6274
*/
public function testCanAddConstantsWithArrayOfGenerators()
{
$constants = array(
new PropertyGenerator('x', 'value1', PropertyGenerator::FLAG_CONSTANT),
new PropertyGenerator('y', 'value2', PropertyGenerator::FLAG_CONSTANT)
);
$classGenerator = new ClassGenerator();
$classGenerator->addConstants($constants);

$this->assertEquals(count($classGenerator->getConstants()), 2);
$constantX = $classGenerator->getConstant('x');
$constantY = $classGenerator->getConstant('y');
$classGenerator->addConstants(array(
new PropertyGenerator('x', 'value1', PropertyGenerator::FLAG_CONSTANT),
new PropertyGenerator('y', 'value2', PropertyGenerator::FLAG_CONSTANT)
));

$this->assertEquals($constantX->getDefaultValue()->getValue(), 'value1');
$this->assertEquals($constantY->getDefaultValue()->getValue(), 'value2');
$this->assertCount(2, $classGenerator->getConstants());
$this->assertEquals($classGenerator->getConstant('x')->getDefaultValue()->getValue(), 'value1');
$this->assertEquals($classGenerator->getConstant('y')->getDefaultValue()->getValue(), 'value2');
}

/**
* @group 6274
*/
public function testCanAddConstantsWithArrayOfKeyValues()
{
$constants = array(
array( 'name'=> 'x', 'value' => 'value1'),
array('name' => 'y', 'value' => 'value2')
);
$classGenerator = new ClassGenerator();
$classGenerator->addConstants($constants);

$this->assertEquals(count($classGenerator->getConstants()), 2);
$constantX = $classGenerator->getConstant('x');
$constantY = $classGenerator->getConstant('y');
$classGenerator->addConstants(array(
array( 'name'=> 'x', 'value' => 'value1'),
array('name' => 'y', 'value' => 'value2')
));

$this->assertEquals($constantX->getDefaultValue()->getValue(), 'value1');
$this->assertEquals($constantY->getDefaultValue()->getValue(), 'value2');
$this->assertCount(2, $classGenerator->getConstants());
$this->assertEquals($classGenerator->getConstant('x')->getDefaultValue()->getValue(), 'value1');
$this->assertEquals($classGenerator->getConstant('y')->getDefaultValue()->getValue(), 'value2');
}

/**
Expand All @@ -594,7 +590,9 @@ public function testCanAddConstantsWithArrayOfKeyValues()
public function testAddConstantThrowsExceptionWithInvalidName()
{
$this->setExpectedException('InvalidArgumentException');

$classGenerator = new ClassGenerator();

$classGenerator->addConstant(array(), 'value1');
}

Expand All @@ -604,7 +602,9 @@ public function testAddConstantThrowsExceptionWithInvalidName()
public function testAddConstantThrowsExceptionWithInvalidValue()
{
$this->setExpectedException('InvalidArgumentException');

$classGenerator = new ClassGenerator();

$classGenerator->addConstant('x', null);
}

Expand All @@ -614,7 +614,9 @@ public function testAddConstantThrowsExceptionWithInvalidValue()
public function testAddConstantThrowsExceptionOnDuplicate()
{
$this->setExpectedException('InvalidArgumentException');

$classGenerator = new ClassGenerator();

$classGenerator->addConstant('x', 'value1');
$classGenerator->addConstant('x', 'value1');
}
Expand All @@ -625,11 +627,10 @@ public function testAddConstantThrowsExceptionOnDuplicate()
public function testAddPropertyIsBackwardsCompatibleWithConstants()
{
$classGenerator = new ClassGenerator();
$classGenerator->addProperty('x', 'value1', PropertyGenerator::FLAG_CONSTANT);

$constantX = $classGenerator->getConstant('x');
$classGenerator->addProperty('x', 'value1', PropertyGenerator::FLAG_CONSTANT);

$this->assertEquals($constantX->getDefaultValue()->getValue(), 'value1');
$this->assertEquals($classGenerator->getConstant('x')->getDefaultValue()->getValue(), 'value1');
}

/**
Expand All @@ -642,25 +643,23 @@ public function testAddPropertiesIsBackwardsCompatibleWithConstants()
new PropertyGenerator('y', 'value2', PropertyGenerator::FLAG_CONSTANT)
);
$classGenerator = new ClassGenerator();
$classGenerator->addProperties($constants);

$this->assertEquals(count($classGenerator->getConstants()), 2);
$constantX = $classGenerator->getConstant('x');
$constantY = $classGenerator->getConstant('y');
$classGenerator->addProperties($constants);

$this->assertEquals($constantX->getDefaultValue()->getValue(), 'value1');
$this->assertEquals($constantY->getDefaultValue()->getValue(), 'value2');
$this->assertCount(2, $classGenerator->getConstants());
$this->assertEquals($classGenerator->getConstant('x')->getDefaultValue()->getValue(), 'value1');
$this->assertEquals($classGenerator->getConstant('y')->getDefaultValue()->getValue(), 'value2');
}

/**
* @group 6274
*/
public function testConstantsAddedFromReflection()
{
$reflector = new ClassReflection('ZendTest\Code\Generator\TestAsset\TestClassWithManyProperties');
$reflector = new ClassReflection('ZendTest\Code\Generator\TestAsset\TestClassWithManyProperties');
$classGenerator = ClassGenerator::fromReflection($reflector);
$constant = $classGenerator->getConstant('FOO');

$constant = $classGenerator->getConstant('FOO');
$this->assertEquals($constant->getDefaultValue()->getValue(), 'foo');
}

Expand All @@ -669,8 +668,9 @@ public function testConstantsAddedFromReflection()
*/
public function testClassCanBeGeneratedWithConstantAndPropertyWithSameName()
{
$reflector = new ClassReflection('ZendTest\Code\Generator\TestAsset\TestSampleSingleClass');
$reflector = new ClassReflection('ZendTest\Code\Generator\TestAsset\TestSampleSingleClass');
$classGenerator = ClassGenerator::fromReflection($reflector);

$classGenerator->addProperty('fooProperty', true, PropertyGenerator::FLAG_PUBLIC);
$classGenerator->addConstant('fooProperty', 'duplicate');

Expand Down

0 comments on commit 1885e1e

Please sign in to comment.