[OptionsResolver] fix counting of options
and make sure the tests are compatible with phpunit strict mode
This commit is contained in:
parent
23f0411a40
commit
6c2130f578
@ -932,6 +932,8 @@ class OptionsResolver implements Options, OptionsResolverInterface
|
||||
*
|
||||
* @return bool Whether the option is set
|
||||
*
|
||||
* @throws AccessException If accessing this method outside of {@link resolve()}
|
||||
*
|
||||
* @see \ArrayAccess::offsetExists()
|
||||
*/
|
||||
public function offsetExists($option)
|
||||
@ -964,7 +966,15 @@ class OptionsResolver implements Options, OptionsResolverInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
* Returns the number of set options.
|
||||
*
|
||||
* This may be only a subset of the defined options.
|
||||
*
|
||||
* @return int Number of options
|
||||
*
|
||||
* @throws AccessException If accessing this method outside of {@link resolve()}
|
||||
*
|
||||
* @see \Countable::count()
|
||||
*/
|
||||
public function count()
|
||||
{
|
||||
@ -972,7 +982,7 @@ class OptionsResolver implements Options, OptionsResolverInterface
|
||||
throw new AccessException('Counting is only supported within closures of lazy options and normalizers.');
|
||||
}
|
||||
|
||||
return count($this->resolved);
|
||||
return count($this->defaults);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -256,14 +256,14 @@ class OptionsResolver2Dot6Test extends \PHPUnit_Framework_TestCase
|
||||
$this->resolver->setRequired('foo');
|
||||
$this->resolver->setDefault('foo', 'bar');
|
||||
|
||||
$this->resolver->resolve();
|
||||
$this->assertNotEmpty($this->resolver->resolve());
|
||||
}
|
||||
|
||||
public function testResolveSucceedsIfRequiredOptionPassed()
|
||||
{
|
||||
$this->resolver->setRequired('foo');
|
||||
|
||||
$this->resolver->resolve(array('foo' => 'bar'));
|
||||
$this->assertNotEmpty($this->resolver->resolve(array('foo' => 'bar')));
|
||||
}
|
||||
|
||||
public function testIsRequired()
|
||||
@ -504,7 +504,7 @@ class OptionsResolver2Dot6Test extends \PHPUnit_Framework_TestCase
|
||||
$this->resolver->setDefault('foo', 'bar');
|
||||
$this->resolver->setAllowedTypes('foo', 'string');
|
||||
|
||||
$this->resolver->resolve();
|
||||
$this->assertNotEmpty($this->resolver->resolve());
|
||||
}
|
||||
|
||||
/**
|
||||
@ -523,7 +523,7 @@ class OptionsResolver2Dot6Test extends \PHPUnit_Framework_TestCase
|
||||
$this->resolver->setDefault('foo', true);
|
||||
$this->resolver->setAllowedTypes('foo', array('string', 'bool'));
|
||||
|
||||
$this->resolver->resolve();
|
||||
$this->assertNotEmpty($this->resolver->resolve());
|
||||
}
|
||||
|
||||
/**
|
||||
@ -542,7 +542,7 @@ class OptionsResolver2Dot6Test extends \PHPUnit_Framework_TestCase
|
||||
$this->resolver->setDefault('foo', new \stdClass());
|
||||
$this->resolver->setAllowedTypes('foo', '\stdClass');
|
||||
|
||||
$this->resolver->resolve();
|
||||
$this->assertNotEmpty($this->resolver->resolve());
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
@ -587,7 +587,7 @@ class OptionsResolver2Dot6Test extends \PHPUnit_Framework_TestCase
|
||||
$this->resolver->setDefault('foo', 'bar');
|
||||
$this->resolver->addAllowedTypes('foo', 'string');
|
||||
|
||||
$this->resolver->resolve();
|
||||
$this->assertNotEmpty($this->resolver->resolve());
|
||||
}
|
||||
|
||||
/**
|
||||
@ -606,7 +606,7 @@ class OptionsResolver2Dot6Test extends \PHPUnit_Framework_TestCase
|
||||
$this->resolver->setDefault('foo', 'bar');
|
||||
$this->resolver->addAllowedTypes('foo', array('string', 'bool'));
|
||||
|
||||
$this->resolver->resolve();
|
||||
$this->assertNotEmpty($this->resolver->resolve());
|
||||
}
|
||||
|
||||
public function testAddAllowedTypesDoesNotOverwrite()
|
||||
@ -617,7 +617,7 @@ class OptionsResolver2Dot6Test extends \PHPUnit_Framework_TestCase
|
||||
|
||||
$this->resolver->setDefault('foo', 'bar');
|
||||
|
||||
$this->resolver->resolve();
|
||||
$this->assertNotEmpty($this->resolver->resolve());
|
||||
}
|
||||
|
||||
public function testAddAllowedTypesDoesNotOverwrite2()
|
||||
@ -628,7 +628,7 @@ class OptionsResolver2Dot6Test extends \PHPUnit_Framework_TestCase
|
||||
|
||||
$this->resolver->setDefault('foo', false);
|
||||
|
||||
$this->resolver->resolve();
|
||||
$this->assertNotEmpty($this->resolver->resolve());
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
@ -1078,7 +1078,7 @@ class OptionsResolver2Dot6Test extends \PHPUnit_Framework_TestCase
|
||||
\PHPUnit_Framework_Assert::fail('Should not be called.');
|
||||
});
|
||||
|
||||
$this->resolver->resolve();
|
||||
$this->assertEmpty($this->resolver->resolve());
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
@ -1208,7 +1208,7 @@ class OptionsResolver2Dot6Test extends \PHPUnit_Framework_TestCase
|
||||
|
||||
public function testRemoveUnknownOptionIgnored()
|
||||
{
|
||||
$this->resolver->remove('foo');
|
||||
$this->assertNotNull($this->resolver->remove('foo'));
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
@ -1427,8 +1427,10 @@ class OptionsResolver2Dot6Test extends \PHPUnit_Framework_TestCase
|
||||
$this->resolver->setDefault('lazy1', function () {});
|
||||
|
||||
$this->resolver->setDefault('lazy2', function (Options $options) {
|
||||
\PHPUnit_Framework_Assert::assertCount(3, $options);
|
||||
\PHPUnit_Framework_Assert::assertCount(4, $options);
|
||||
});
|
||||
|
||||
$this->assertCount(4, $this->resolver->resolve(array('required' => 'value')));
|
||||
}
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user