Skip to content

Commit b754595

Browse files
committed
refactor Storage classes
1 parent 4ff3de7 commit b754595

File tree

5 files changed

+45
-136
lines changed

5 files changed

+45
-136
lines changed

lib/WebDriver/ClassLoader.php

Lines changed: 0 additions & 86 deletions
This file was deleted.

lib/WebDriver/Session.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -401,7 +401,7 @@ public function touch()
401401
*/
402402
public function localStorage()
403403
{
404-
return Storage::factory('local', $this->url . '/local_storage', $this->w3c);
404+
return new Storage\Local($this->url . '/local_storage', $this->w3c);
405405
}
406406

407407
/**
@@ -412,7 +412,7 @@ public function localStorage()
412412
*/
413413
public function sessionStorage()
414414
{
415-
return Storage::factory('session', $this->url . '/session_storage', $this->w3c);
415+
return new Storage\Session($this->url . '/session_storage', $this->w3c);
416416
}
417417

418418
/**

lib/WebDriver/Storage.php renamed to lib/WebDriver/Storage/AbstractStorage.php

Lines changed: 6 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -20,20 +20,21 @@
2020
* @author Anthon Pang <[email protected]>
2121
*/
2222

23-
namespace WebDriver;
23+
namespace WebDriver\Storage;
2424

25+
use WebDriver\AbstractWebDriver;
2526
use WebDriver\Exception as WebDriverException;
2627

2728
/**
28-
* WebDriver\Storage class
29+
* WebDriver\AbstractStorage class
2930
*
3031
* @package WebDriver
3132
*
3233
* @method mixed getKey($key) Get key/value pair.
3334
* @method void deleteKey($key) Delete a specific key.
3435
* @method integer size() Get the number of items in the storage.
3536
*/
36-
abstract class Storage extends AbstractWebDriver
37+
abstract class AbstractStorage extends AbstractWebDriver
3738
{
3839
/**
3940
* {@inheritdoc}
@@ -71,7 +72,7 @@ public function get()
7172
/**
7273
* Set specific key/value pair
7374
*
74-
* @return \WebDriver\Storage
75+
* @return \WebDriver\AbstractStorage
7576
*
7677
* @throw \WebDriver\Exception\UnexpectedParameters if unexpected parameters
7778
*/
@@ -102,7 +103,7 @@ public function set()
102103
/**
103104
* Delete storage or a specific key
104105
*
105-
* @return \WebDriver\Storage
106+
* @return \WebDriver\AbstractStorage
106107
*
107108
* @throw \WebDriver\Exception\UnexpectedParameters if unexpected parameters
108109
*/
@@ -124,28 +125,4 @@ public function delete()
124125

125126
throw WebDriverException::factory(WebDriverException::UNEXPECTED_PARAMETERS);
126127
}
127-
128-
/**
129-
* Factory method to create Storage objects
130-
*
131-
* @param string $type 'local' or 'session' storage
132-
* @param string $url URL
133-
* @param boolean $w3c Is W3C?
134-
*
135-
* @return \WebDriver\Storage
136-
*/
137-
public static function factory($type, $url, $w3c = false)
138-
{
139-
// dynamically define custom storage classes
140-
$className = ucfirst(strtolower($type));
141-
$namespacedClassName = __CLASS__ . '\\' . $className;
142-
143-
if (! class_exists($namespacedClassName, false)) {
144-
eval(
145-
'namespace ' . __CLASS__ . '; final class ' . $className . ' extends \\' . __CLASS__ . '{}'
146-
);
147-
}
148-
149-
return new $namespacedClassName($url, $w3c);
150-
}
151128
}
Lines changed: 5 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<?php
2+
23
/**
3-
* Copyright 2011-2017 Anthon Pang. All Rights Reserved.
4+
* Copyright 2021-2021 Anthon Pang. All Rights Reserved.
45
*
56
* Licensed under the Apache License, Version 2.0 (the "License");
67
* you may not use this file except in compliance with the License.
@@ -19,28 +20,13 @@
1920
* @author Anthon Pang <[email protected]>
2021
*/
2122

22-
namespace Test\WebDriver;
23-
24-
use WebDriver\Storage;
23+
namespace WebDriver\Storage;
2524

2625
/**
27-
* Test WebDriver\Storage class
26+
* WebDriver\Storage\Local class
2827
*
2928
* @package WebDriver
30-
*
31-
* @group Unit
3229
*/
33-
class StorageTest extends \PHPUnit_Framework_TestCase
30+
final class Local extends AbstractStorage
3431
{
35-
/**
36-
* test factory()
37-
*/
38-
public function testFactory()
39-
{
40-
$out = Storage::factory('Local', '/');
41-
$this->assertTrue($out instanceof Storage\Local);
42-
43-
$out = Storage::factory('sEsSiOn', '/');
44-
$this->assertTrue($out instanceof Storage\Session);
45-
}
4632
}

lib/WebDriver/Storage/Session.php

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php
2+
3+
/**
4+
* Copyright 2021-2021 Anthon Pang. All Rights Reserved.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*
18+
* @package WebDriver
19+
*
20+
* @author Anthon Pang <[email protected]>
21+
*/
22+
23+
namespace WebDriver\Storage;
24+
25+
/**
26+
* WebDriver\Storage\Session class
27+
*
28+
* @package WebDriver
29+
*/
30+
final class Session extends AbstractStorage
31+
{
32+
}

0 commit comments

Comments
 (0)