Completed
Push — develop ( 8387b5...1b51bd )
by Daniel
11:34
created

base_mapper::get_mapper()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 29
Code Lines 19

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 29
c 0
b 0
f 0
ccs 0
cts 23
cp 0
rs 8.8571
cc 1
eloc 19
nc 1
nop 1
crap 2
1
<?php
2
/**
3
 *
4
 * @package sitemaker
5
 * @copyright (c) 2015 Daniel A. (blitze)
6
 * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
7
 *
8
 */
9
10
namespace blitze\sitemaker\tests\model\mapper;
11
12
class base_mapper extends \phpbb_database_test_case
13
{
14
	protected $config;
15
16
	/**
17
	 * Define the extension to be tested.
18
	 *
19
	 * @return string[]
20
	 */
21
	protected static function setup_extensions()
22
	{
23
		return array('blitze/sitemaker');
24
	}
25
26
	/**
27
	 * Load required fixtures.
28
	 *
29
	 * @return mixed
30
	 */
31
	public function getDataSet()
32
	{
33
		return $this->createXMLDataSet(dirname(__FILE__) . '/fixtures/menu.xml');
34
	}
35
36
	public function setUp()
37
	{
38
		parent::setUp();
39
40
		global $config;
41
42
		$config = $this->config = new \phpbb\config\config(array(
43
			'force_server_vars' => false,
44
			'sitemaker.table_lock.menu_items_table' => 0
45
		));
46
	}
47
48
	/**
49
	 * Create the blocks mapper
50
	 * @param string $type
51
	 * @return mixed
52
	 */
53
	protected function get_mapper($type)
54
	{
55
		global $db, $request, $user;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
56
57
		$table_prefix = 'phpbb_';
58
		$collection_class = '\\blitze\\sitemaker\\model\\menus\\collections\\' . $type;
59
		$mapper_class = '\\blitze\\sitemaker\\model\\menus\\mapper\\' . $type;
60
		$tables = array(
61
			'mapper_tables'	=> array(
62
				'menus'	=> $table_prefix . 'sm_menus',
63
				'items'	=> $table_prefix . 'sm_menu_items'
64
			)
65
		);
66
67
		$db = $this->new_dbal();
68
69
		$request = $this->getMock('\phpbb\request\request_interface');
70
71
		$user = $this->getMockBuilder('\phpbb\user')
72
			->disableOriginalConstructor()
73
			->getMock();
74
		$user->host = 'www.example.com';
75
		$user->page['root_script_path'] = '/phpBB/';
76
77
		$mapper_factory = new \blitze\sitemaker\model\mapper_factory($this->config, $db, $tables);
78
		$collection = new $collection_class;
79
80
		return new $mapper_class($db, $collection, $mapper_factory, $tables['mapper_tables'][$type], $this->config);
81
	}
82
}
83