Skip to content

Commit

Permalink
[TASK] Make form/Tests/Unit/Domain/FormElements/ notice free
Browse files Browse the repository at this point in the history
Releases: master
Resolves: #84397
Change-Id: I0882fa642505bd2122885b83538d6f32ddbee293
Reviewed-on: https://review.typo3.org/56273
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Anja Leichsenring <aleichsenring@ab-softlab.de>
Tested-by: Anja Leichsenring <aleichsenring@ab-softlab.de>
Reviewed-by: Christian Kuhn <lolli@schwarzbu.ch>
Tested-by: Christian Kuhn <lolli@schwarzbu.ch>
  • Loading branch information
janhelke authored and lolli42 committed Mar 17, 2018
1 parent cd210dd commit b924a8e
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 32 deletions.
Expand Up @@ -147,7 +147,7 @@ public function isRequired(): bool
*/
public function setProperty(string $key, $value)
{
if (is_array($value) && is_array($this->properties[$key])) {
if (is_array($value) && isset($this->properties[$key]) && is_array($this->properties[$key])) {
ArrayUtility::mergeRecursiveWithOverrule($this->properties[$key], $value);
} else {
$this->properties[$key] = $value;
Expand Down
Expand Up @@ -117,7 +117,7 @@ public function getProperties(): array
*/
public function setProperty(string $key, $value)
{
if (is_array($value) && is_array($this->properties[$key])) {
if (is_array($value) && isset($this->properties[$key]) && is_array($this->properties[$key])) {
ArrayUtility::mergeRecursiveWithOverrule($this->properties[$key], $value);
} else {
$this->properties[$key] = $value;
Expand Down
Expand Up @@ -13,15 +13,10 @@
*/
class AbstractFormElementTest extends UnitTestCase
{
/**
* Subject is not notice free, disable E_NOTICES
*/
protected static $suppressNotices = true;

/**
* @test
*/
public function newInstanceHasNoProperties()
public function newInstanceHasNoProperties(): void
{
/** @var AbstractFormElement $subject */
$subject = $this->getMockForAbstractClass(AbstractFormElement::class, ['an_id', 'a_type']);
Expand All @@ -32,7 +27,7 @@ public function newInstanceHasNoProperties()
/**
* @test
*/
public function setSimpleProperties()
public function setSimpleProperties(): void
{
/** @var AbstractFormElement $subject */
$subject = $this->getMockForAbstractClass(AbstractFormElement::class, ['an_id', 'a_type']);
Expand All @@ -51,7 +46,7 @@ public function setSimpleProperties()
/**
* @test
*/
public function overrideProperties()
public function overrideProperties(): void
{
/** @var AbstractFormElement $subject */
$subject = $this->getMockForAbstractClass(AbstractFormElement::class, ['an_id', 'a_type']);
Expand All @@ -60,15 +55,15 @@ public function overrideProperties()
$subject->setProperty('foo', 'buz');

$properties = $subject->getProperties();
$this->assertEquals(1, count($properties));
$this->assertEquals(1, \count($properties));
$this->assertTrue(array_key_exists('foo', $properties));
$this->assertEquals('buz', $properties['foo']);
}

/**
* @test
*/
public function setArrayProperties()
public function setArrayProperties(): void
{
/** @var AbstractFormElement $subject */
$subject = $this->getMockForAbstractClass(AbstractFormElement::class, ['an_id', 'a_type']);
Expand All @@ -80,7 +75,7 @@ public function setArrayProperties()
$this->assertTrue(array_key_exists('foo', $properties));

//check arrays details
$this->assertTrue(is_array($properties['foo']));
$this->assertTrue(\is_array($properties['foo']));
$this->assertCount(2, $properties['foo']);
$this->assertTrue(array_key_exists('bar', $properties['foo']));
$this->assertEquals('baz', $properties['foo']['bar']);
Expand All @@ -89,7 +84,7 @@ public function setArrayProperties()
/**
* @test
*/
public function constructThrowsExceptionWhenIdentifierIsEmpty()
public function constructThrowsExceptionWhenIdentifierIsEmpty(): void
{
$this->expectException(IdentifierNotValidException::class);
$this->expectExceptionCode(1477082502);
Expand All @@ -108,7 +103,7 @@ public function constructThrowsExceptionWhenIdentifierIsEmpty()
/**
* @test
*/
public function constructMustNotThrowExceptionWhenIdentifierIsNonEmptyString()
public function constructMustNotThrowExceptionWhenIdentifierIsNonEmptyString(): void
{
$mock = $this->getAccessibleMockForAbstractClass(
AbstractFormElement::class,
Expand All @@ -125,7 +120,7 @@ public function constructMustNotThrowExceptionWhenIdentifierIsNonEmptyString()
/**
* @test
*/
public function initializeFormElementExpectedCallInitializeFormObjectHooks()
public function initializeFormElementExpectedCallInitializeFormObjectHooks(): void
{
/** @var \PHPUnit_Framework_MockObject_MockObject|\TYPO3\TestingFramework\Core\AccessibleObjectInterface|AbstractFormElement $abstractFormElementMock */
$abstractFormElementMock = $this->getAccessibleMockForAbstractClass(
Expand Down Expand Up @@ -155,10 +150,10 @@ public function initializeFormElementExpectedCallInitializeFormObjectHooks()
->method('initializeFormElement')
->with($abstractFormElementMock);

GeneralUtility::addInstance(get_class($secondMock), $secondMock);
GeneralUtility::addInstance(\get_class($secondMock), $secondMock);

$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['ext/form']['initializeFormElement'] = [
get_class($secondMock)
\get_class($secondMock)
];

$abstractFormElementMock->initializeFormElement();
Expand All @@ -167,7 +162,7 @@ public function initializeFormElementExpectedCallInitializeFormObjectHooks()
/**
* @test
*/
public function getUniqueIdentifierExpectedUnique()
public function getUniqueIdentifierExpectedUnique(): void
{
/** @var \PHPUnit_Framework_MockObject_MockObject|\TYPO3\TestingFramework\Core\AccessibleObjectInterface|AbstractFormElement $abstractFormElementMock1 */
$abstractFormElementMock1 = $this->getAccessibleMockForAbstractClass(
Expand Down
23 changes: 10 additions & 13 deletions typo3/sysext/form/Tests/Unit/Domain/FormElements/SectionTest.php
@@ -1,28 +1,25 @@
<?php
declare(strict_types = 1);
namespace TYPO3\CMS\Form\Tests\Unit\Domain\FormElements;

use TYPO3\CMS\Form\Domain\Model\FormElements\Section;
use TYPO3\TestingFramework\Core\Unit\UnitTestCase;

/**
* Test TYPO3\CMS\Form\Domain\Model\FormElements\Section class
*
* Class AbstractFormElementTest
*/
class SectionTest extends \TYPO3\TestingFramework\Core\Unit\UnitTestCase
class SectionTest extends UnitTestCase
{
/**
* Subject is not notice free, disable E_NOTICES
*/
protected static $suppressNotices = true;

protected static $IDENTIFIER = 'an_id';
protected static $TYPE = 'a_type';

/**
* An instance of section
* @var Section
*/
protected $sectionInstance = null;
protected $sectionInstance;

/**
* @before
Expand All @@ -36,7 +33,7 @@ public function setUp()
/**
* @test
*/
public function newInstanceHasNoProperties()
public function newInstanceHasNoProperties(): void
{
$this->assertNotNull($this->sectionInstance);
$this->assertCount(0, $this->sectionInstance->getProperties());
Expand All @@ -45,7 +42,7 @@ public function newInstanceHasNoProperties()
/**
* @test
*/
public function setSimpleProperties()
public function setSimpleProperties(): void
{
$this->sectionInstance->setProperty('foo', 'bar');
$this->sectionInstance->setProperty('buz', 'qax');
Expand All @@ -61,21 +58,21 @@ public function setSimpleProperties()
/**
* @test
*/
public function overrideProperties()
public function overrideProperties(): void
{
$this->sectionInstance->setProperty('foo', 'bar');
$this->sectionInstance->setProperty('foo', 'buz');

$properties = $this->sectionInstance->getProperties();
$this->assertEquals(1, count($properties));
$this->assertEquals(1, \count($properties));
$this->assertTrue(array_key_exists('foo', $properties));
$this->assertEquals('buz', $properties['foo']);
}

/**
* @test
*/
public function setArrayProperties()
public function setArrayProperties(): void
{
$this->sectionInstance->setProperty('foo', ['bar' => 'baz', 'bla' => 'blubb']);
$properties = $this->sectionInstance->getProperties();
Expand All @@ -84,7 +81,7 @@ public function setArrayProperties()
$this->assertTrue(array_key_exists('foo', $properties));

//check arrays details
$this->assertTrue(is_array($properties['foo']));
$this->assertTrue(\is_array($properties['foo']));
$this->assertCount(2, $properties['foo']);
$this->assertTrue(array_key_exists('bar', $properties['foo']));
$this->assertEquals('baz', $properties['foo']['bar']);
Expand Down

0 comments on commit b924a8e

Please sign in to comment.