blob: f500c3e244d5a2319fd6061900219941608bae3a (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
|
<?php
/**
* Piwik - free/libre analytics platform
*
* @link https://matomo.org
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
*/
namespace Piwik\Tests\Integration\Tracker\Handler;
use Piwik\EventDispatcher;
use Piwik\Piwik;
use Piwik\Tests\Framework\TestCase\IntegrationTestCase;
use Piwik\Tracker;
use Piwik\Tracker\Handler;
use Piwik\Tracker\Handler\Factory;
/**
* @group Tracker
* @group Handler
* @group Factory
* @group FactoryTest
*/
class FactoryTest extends IntegrationTestCase
{
public function test_make_shouldCreateDefaultInstance()
{
$handler = Factory::make();
$this->assertInstanceOf('Piwik\\Tracker\\Handler', $handler);
}
public function test_make_shouldTriggerEventOnce()
{
$called = 0;
$self = $this;
Piwik::addAction('Tracker.newHandler', function ($handler) use (&$called, $self) {
$called++;
$self->assertNull($handler);
});
Factory::make();
$this->assertSame(1, $called);
}
public function test_make_shouldPreferManuallyCreatedHandlerInstanceInEventOverDefaultHandler()
{
$handlerToUse = new Handler();
Piwik::addAction('Tracker.newHandler', function (&$handler) use ($handlerToUse) {
$handler = $handlerToUse;
});
$handler = Factory::make();
$this->assertSame($handlerToUse, $handler);
}
public function test_make_shouldTriggerExceptionInCaseWrongInstanceCreatedInHandler()
{
$this->expectException(\Exception::class);
$this->expectExceptionMessage('The Handler object set in the plugin');
Piwik::addAction('Tracker.newHandler', function (&$handler) {
$handler = new Tracker();
});
Factory::make();
}
}
|