Passed
Branch master (b37043)
by Timo
11:18
created

DevLogDebugWriterTest   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 63
Duplicated Lines 69.84 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 2
Bugs 1 Features 2
Metric Value
dl 44
loc 63
rs 10
c 2
b 1
f 2
wmc 4
lcom 1
cbo 3

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
namespace ApacheSolrForTypo3\Solr\Tests\Unit\System\Configuration;
3
4
/***************************************************************
5
 *  Copyright notice
6
 *
7
 *  (c) 2011-2016 Timo Hund <[email protected]>
8
 *  All rights reserved
9
 *
10
 *  This script is part of the TYPO3 project. The TYPO3 project is
11
 *  free software; you can redistribute it and/or modify
12
 *  it under the terms of the GNU General Public License as published by
13
 *  the Free Software Foundation; either version 2 of the License, or
14
 *  (at your option) any later version.
15
 *
16
 *  The GNU General Public License can be found at
17
 *  http://www.gnu.org/copyleft/gpl.html.
18
 *
19
 *  This script is distributed in the hope that it will be useful,
20
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
21
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
22
 *  GNU General Public License for more details.
23
 *
24
 *  This copyright notice MUST APPEAR in all copies of the script!
25
 ***************************************************************/
26
27
use ApacheSolrForTypo3\Solr\System\Configuration\TypoScriptConfiguration;
28
use ApacheSolrForTypo3\Solr\System\Logging\DevLogDebugWriter;
29
use ApacheSolrForTypo3\Solr\Tests\Unit\UnitTest;
30
use TYPO3\CMS\Core\Utility\GeneralUtility;
31
32
/**
33
 * @author Timo Hund <[email protected]>
34
 * @package TYPO3
35
 * @subpackage solr
36
 */
37
class DevLogDebugWriterTest extends UnitTest
38
{
39
40
    /**
41
     * @test
42
     */
43
    public function testDebugMessageIsWrittenForMessageFromSolr()
44
    {
45
        /** @var $logWriter DevLogDebugWriter */
46
        $logWriter = $this->getMockBuilder(DevLogDebugWriter::class)->setMethods(['getIsAllowedByDevIPMask', 'getIsDevLogDebugOutputEnabled', 'writeDebugMessage'])->getMock();
47
        $logWriter->expects($this->any())->method('getIsAllowedByDevIPMask')->will($this->returnValue(true));
48
        $logWriter->expects($this->any())->method('getIsDevLogDebugOutputEnabled')->will($this->returnValue(true));
49
50
            //we have a matching devIpMask and the debugOutput of log messages is enabled => debug should be written
51
        $logWriter->expects($this->once())->method('writeDebugMessage');
52
        $logWriter->log(['extKey' => 'solr', 'message' => 'test']);
53
    }
54
55
    /**
56
     * @test
57
     */
58
    public function testDebugMessageIsNotWrittenForOtherExtensions()
59
    {
60
        /** @var $logWriter DevLogDebugWriter */
61
        $logWriter = $this->getMockBuilder(DevLogDebugWriter::class)->setMethods(['getIsAllowedByDevIPMask', 'getIsDevLogDebugOutputEnabled', 'writeDebugMessage'])->getMock();
62
        $logWriter->expects($this->any())->method('getIsAllowedByDevIPMask')->will($this->returnValue(true));
63
        $logWriter->expects($this->any())->method('getIsDevLogDebugOutputEnabled')->will($this->returnValue(true));
64
65
        //we have a matching devIpMask and the debugOutput of log messages is enabled => debug should be written
66
        $logWriter->expects($this->never())->method('writeDebugMessage');
67
        $logWriter->log(['extKey' => 'news', 'message' => 'test']);
68
    }
69
70
    /**
71
     * @test
72
     */
73
    public function testDebugMessageIsNotWrittenWhenDevIpMaskIsNotMatching()
74
    {
75
        /** @var $logWriter DevLogDebugWriter */
76
        $logWriter = $this->getMockBuilder(DevLogDebugWriter::class)->setMethods(['getIsAllowedByDevIPMask', 'getIsDevLogDebugOutputEnabled', 'writeDebugMessage'])->getMock();
77
        $logWriter->expects($this->any())->method('getIsAllowedByDevIPMask')->will($this->returnValue(false));
78
        $logWriter->expects($this->any())->method('getIsDevLogDebugOutputEnabled')->will($this->returnValue(true));
79
80
        //we have a matching devIpMask and the debugOutput of log messages is enabled => debug should be written
81
        $logWriter->expects($this->never())->method('writeDebugMessage');
82
        $logWriter->log(['extKey' => 'solr', 'message' => 'test']);
83
    }
84
85
    /**
86
     * @test
87
     */
88
    public function testDebugMessageIsNotWrittenWhenDebugOutputIsDisabled()
89
    {
90
        /** @var $logWriter DevLogDebugWriter */
91
        $logWriter = $this->getMockBuilder(DevLogDebugWriter::class)->setMethods(['getIsAllowedByDevIPMask', 'getIsDevLogDebugOutputEnabled', 'writeDebugMessage'])->getMock();
92
        $logWriter->expects($this->any())->method('getIsAllowedByDevIPMask')->will($this->returnValue(true));
93
        $logWriter->expects($this->any())->method('getIsDevLogDebugOutputEnabled')->will($this->returnValue(false));
94
95
        //we have a matching devIpMask and the debugOutput of log messages is enabled => debug should be written
96
        $logWriter->expects($this->never())->method('writeDebugMessage');
97
        $logWriter->log(['extKey' => 'solr', 'message' => 'test']);
98
    }
99
}
100