Skip to content

Commit d3fb46c

Browse files
author
Alexander Obuhovich
authored
Merge pull request #189 from aik099/config-missing-tests
Add missing tests for "Config" class
2 parents a1ae707 + caad69a commit d3fb46c

File tree

2 files changed

+57
-14
lines changed

2 files changed

+57
-14
lines changed

library/QATools/QATools/PageObject/Config/Config.php

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -55,16 +55,10 @@ public function __construct(array $options = array())
5555
* @param mixed $value Config option value.
5656
*
5757
* @return self
58-
* @throws ConfigException Throws exception on attempt to set non-existing option.
5958
*/
6059
public function setOption($name, $value)
6160
{
62-
if ( !isset($this->options[$name]) ) {
63-
throw new ConfigException(
64-
'Option "' . $name . '" doesn\'t exist in configuration',
65-
ConfigException::TYPE_NOT_FOUND
66-
);
67-
}
61+
$this->assertOptionName($name);
6862

6963
$this->options[$name] = $value;
7064

@@ -77,18 +71,30 @@ public function setOption($name, $value)
7771
* @param string $name Config option name.
7872
*
7973
* @return mixed
80-
* @throws ConfigException Thrown when option with a given name doesn't exist.
8174
*/
8275
public function getOption($name)
76+
{
77+
$this->assertOptionName($name);
78+
79+
return $this->options[$name];
80+
}
81+
82+
/**
83+
* Checks, that option exists in config.
84+
*
85+
* @param string $name Option name.
86+
*
87+
* @return void
88+
* @throws ConfigException Thrown when option with a given name doesn't exist.
89+
*/
90+
protected function assertOptionName($name)
8391
{
8492
if ( !isset($this->options[$name]) ) {
8593
throw new ConfigException(
8694
'Option "' . $name . '" doesn\'t exist in configuration',
8795
ConfigException::TYPE_NOT_FOUND
8896
);
8997
}
90-
91-
return $this->options[$name];
9298
}
9399

94100
}

tests/QATools/QATools/PageObject/Config/ConfigTest.php

Lines changed: 41 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,31 @@ public function constructorDataProvider()
3636
return array(
3737
array(
3838
array(),
39-
array('base_url' => ''),
39+
array(
40+
'base_url' => '',
41+
'page_namespace_prefix' => array('\\'),
42+
'page_url_matchers' => array(
43+
'\\QATools\\QATools\\PageObject\\PageUrlMatcher\\ExactPageUrlMatcher',
44+
'\\QATools\\QATools\\PageObject\\PageUrlMatcher\\RegexpPageUrlMatcher',
45+
'\\QATools\\QATools\\PageObject\\PageUrlMatcher\\ComponentPageUrlMatcher',
46+
),
47+
),
4048
),
4149
array(
42-
array('base_url' => 'value'),
43-
array('base_url' => 'value'),
50+
array(
51+
'base_url' => 'override',
52+
'page_namespace_prefix' => array('\\CustomNS'),
53+
'page_url_matchers' => array(
54+
'CustomPageUrlMatcher',
55+
),
56+
),
57+
array(
58+
'base_url' => 'override',
59+
'page_namespace_prefix' => array('\\CustomNS'),
60+
'page_url_matchers' => array(
61+
'CustomPageUrlMatcher',
62+
),
63+
),
4464
),
4565
);
4666
}
@@ -70,7 +90,9 @@ public function testSetAndGetOption($name, $value)
7090
public function optionDataProvider()
7191
{
7292
return array(
73-
array('base_url', 'value'),
93+
array('base_url', 'override1'),
94+
array('page_namespace_prefix', 'override2'),
95+
array('page_url_matchers', 'override3'),
7496
);
7597
}
7698

@@ -89,6 +111,21 @@ public function testGetOptionWithFailure(array $options, $name)
89111
$config->getOption($name);
90112
}
91113

114+
/**
115+
* @dataProvider getOptionWithFailureDataProvider
116+
*/
117+
public function testSetOptionWithFailure(array $options, $name)
118+
{
119+
$this->setExpectedException(
120+
'QATools\\QATools\\PageObject\\Exception\\ConfigException',
121+
'Option "' . $name . '" doesn\'t exist in configuration',
122+
ConfigException::TYPE_NOT_FOUND
123+
);
124+
125+
$config = new Config($options);
126+
$config->setOption($name, 'x');
127+
}
128+
92129
public function getOptionWithFailureDataProvider()
93130
{
94131
return array(

0 commit comments

Comments
 (0)