| 1 |
201
|
mapi |
<?php |
|
| 2 |
↓
|
mapi |
/** |
|
| 3 |
↓
|
mapi |
* This file is part of PHP_Depend. |
|
| 4 |
535
|
mapi |
* |
|
| 5 |
201
|
mapi |
* PHP Version 5 |
|
| 6 |
↓
|
mapi |
* |
|
| 7 |
1030
|
mapi |
* Copyright (c) 2008-2010, Manuel Pichler <mapi@pdepend.org>. |
|
| 8 |
201
|
mapi |
* All rights reserved. |
|
| 9 |
↓
|
mapi |
* |
|
| 10 |
↓
|
mapi |
* Redistribution and use in source and binary forms, with or without |
|
| 11 |
↓
|
mapi |
* modification, are permitted provided that the following conditions |
|
| 12 |
↓
|
mapi |
* are met: |
|
| 13 |
↓
|
mapi |
* |
|
| 14 |
↓
|
mapi |
* * Redistributions of source code must retain the above copyright |
|
| 15 |
↓
|
mapi |
* notice, this list of conditions and the following disclaimer. |
|
| 16 |
↓
|
mapi |
* |
|
| 17 |
↓
|
mapi |
* * Redistributions in binary form must reproduce the above copyright |
|
| 18 |
↓
|
mapi |
* notice, this list of conditions and the following disclaimer in |
|
| 19 |
↓
|
mapi |
* the documentation and/or other materials provided with the |
|
| 20 |
↓
|
mapi |
* distribution. |
|
| 21 |
↓
|
mapi |
* |
|
| 22 |
↓
|
mapi |
* * Neither the name of Manuel Pichler nor the names of his |
|
| 23 |
↓
|
mapi |
* contributors may be used to endorse or promote products derived |
|
| 24 |
↓
|
mapi |
* from this software without specific prior written permission. |
|
| 25 |
↓
|
mapi |
* |
|
| 26 |
↓
|
mapi |
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
|
| 27 |
↓
|
mapi |
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
|
| 28 |
↓
|
mapi |
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS |
|
| 29 |
↓
|
mapi |
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE |
|
| 30 |
↓
|
mapi |
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, |
|
| 31 |
↓
|
mapi |
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, |
|
| 32 |
↓
|
mapi |
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
|
| 33 |
↓
|
mapi |
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
|
| 34 |
↓
|
mapi |
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
|
| 35 |
↓
|
mapi |
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN |
|
| 36 |
↓
|
mapi |
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
|
| 37 |
↓
|
mapi |
* POSSIBILITY OF SUCH DAMAGE. |
|
| 38 |
↓
|
mapi |
* |
|
| 39 |
↓
|
mapi |
* @category QualityAssurance |
|
| 40 |
↓
|
mapi |
* @package PHP_Depend |
|
| 41 |
↓
|
mapi |
* @subpackage Log |
|
| 42 |
269
|
mapi |
* @author Manuel Pichler <mapi@pdepend.org> |
|
| 43 |
1030
|
mapi |
* @copyright 2008-2010 Manuel Pichler. All rights reserved. |
|
| 44 |
201
|
mapi |
* @license http://www.opensource.org/licenses/bsd-license.php BSD License |
|
| 45 |
↓
|
mapi |
* @version SVN: $Id: XmlTest.php 1184 2010-03-18 11:42:20Z mapi $ |
|
| 46 |
824
|
mapi |
* @link http://pdepend.org/ |
|
| 47 |
201
|
mapi |
*/ |
|
| 48 |
↓
|
mapi |
|
|
| 49 |
↓
|
mapi |
require_once dirname(__FILE__) . '/../../AbstractTest.php'; |
|
| 50 |
↓
|
mapi |
require_once dirname(__FILE__) . '/../DummyAnalyzer.php'; |
|
| 51 |
↓
|
mapi |
|
|
| 52 |
↓
|
mapi |
require_once 'PHP/Depend/Log/Jdepend/Xml.php'; |
|
| 53 |
↓
|
mapi |
require_once 'PHP/Depend/Metrics/Dependency/Analyzer.php'; |
|
| 54 |
↓
|
mapi |
|
|
| 55 |
↓
|
mapi |
/** |
|
| 56 |
↓
|
mapi |
* Test case for the jdepend xml logger. |
|
| 57 |
↓
|
mapi |
* |
|
| 58 |
↓
|
mapi |
* @category QualityAssurance |
|
| 59 |
↓
|
mapi |
* @package PHP_Depend |
|
| 60 |
↓
|
mapi |
* @subpackage Log |
|
| 61 |
269
|
mapi |
* @author Manuel Pichler <mapi@pdepend.org> |
|
| 62 |
1030
|
mapi |
* @copyright 2008-2010 Manuel Pichler. All rights reserved. |
|
| 63 |
201
|
mapi |
* @license http://www.opensource.org/licenses/bsd-license.php BSD License |
|
| 64 |
↓
|
mapi |
* @version Release: @package_version@ |
|
| 65 |
824
|
mapi |
* @link http://pdepend.org/ |
|
| 66 |
201
|
mapi |
*/ |
|
| 67 |
↓
|
mapi |
class PHP_Depend_Log_Jdepend_XmlTest extends PHP_Depend_AbstractTest |
|
| 68 |
↓
|
mapi |
{ |
|
| 69 |
↓
|
mapi |
/** |
|
| 70 |
↓
|
mapi |
* Test code structure. |
|
| 71 |
↓
|
mapi |
* |
|
| 72 |
↓
|
mapi |
* @var PHP_Depend_Code_NodeIterator $packages |
|
| 73 |
↓
|
mapi |
*/ |
|
| 74 |
↓
|
mapi |
protected $packages = null; |
|
| 75 |
535
|
mapi |
|
|
| 76 |
201
|
mapi |
/** |
|
| 77 |
↓
|
mapi |
* Test dependency analyzer. |
|
| 78 |
↓
|
mapi |
* |
|
| 79 |
↓
|
mapi |
* @var PHP_Depend_Metrics_Dependency_Analyzer $analyzer |
|
| 80 |
↓
|
mapi |
*/ |
|
| 81 |
↓
|
mapi |
protected $analyzer = null; |
|
| 82 |
535
|
mapi |
|
|
| 83 |
201
|
mapi |
/** |
|
| 84 |
↓
|
mapi |
* The temporary file name for the logger result. |
|
| 85 |
↓
|
mapi |
* |
|
| 86 |
↓
|
mapi |
* @var string $resultFile |
|
| 87 |
↓
|
mapi |
*/ |
|
| 88 |
↓
|
mapi |
protected $resultFile = null; |
|
| 89 |
535
|
mapi |
|
|
| 90 |
201
|
mapi |
/** |
|
| 91 |
↓
|
mapi |
* Creates the package structure from a test source file. |
|
| 92 |
↓
|
mapi |
* |
|
| 93 |
↓
|
mapi |
* @return void |
|
| 94 |
↓
|
mapi |
*/ |
|
| 95 |
↓
|
mapi |
protected function setUp() |
|
| 96 |
↓
|
mapi |
{ |
|
| 97 |
↓
|
mapi |
parent::setUp(); |
|
| 98 |
535
|
mapi |
|
|
| 99 |
606
|
mapi |
$this->packages = self::parseSource(dirname(__FILE__) . '/../../_code/code-5.2.x'); |
|
| 100 |
535
|
mapi |
|
|
| 101 |
201
|
mapi |
$this->analyzer = new PHP_Depend_Metrics_Dependency_Analyzer(); |
|
| 102 |
↓
|
mapi |
$this->analyzer->analyze($this->packages); |
|
| 103 |
535
|
mapi |
|
|
| 104 |
616
|
mapi |
$this->resultFile = self::createRunResourceURI('pdepend-log.xml'); |
|
| 105 |
201
|
mapi |
} |
|
| 106 |
535
|
mapi |
|
|
| 107 |
201
|
mapi |
/** |
|
| 108 |
↓
|
mapi |
* Removes the temporary log files. |
|
| 109 |
↓
|
mapi |
* |
|
| 110 |
↓
|
mapi |
* @return void |
|
| 111 |
↓
|
mapi |
*/ |
|
| 112 |
↓
|
mapi |
protected function tearDown() |
|
| 113 |
↓
|
mapi |
{ |
|
| 114 |
↓
|
mapi |
@unlink($this->resultFile); |
|
| 115 |
535
|
mapi |
|
|
| 116 |
201
|
mapi |
parent::tearDown(); |
|
| 117 |
↓
|
mapi |
} |
|
| 118 |
535
|
mapi |
|
|
| 119 |
201
|
mapi |
/** |
|
| 120 |
352
|
mapi |
* Tests that the logger returns the expected set of analyzers. |
|
| 121 |
↓
|
mapi |
* |
|
| 122 |
↓
|
mapi |
* @return void |
|
| 123 |
↓
|
mapi |
*/ |
|
| 124 |
↓
|
mapi |
public function testReturnsExceptedAnalyzers() |
|
| 125 |
↓
|
mapi |
{ |
|
| 126 |
356
|
mapi |
$logger = new PHP_Depend_Log_Jdepend_Xml(); |
|
| 127 |
352
|
mapi |
$actual = $logger->getAcceptedAnalyzers(); |
|
| 128 |
↓
|
mapi |
$exptected = array('PHP_Depend_Metrics_Dependency_Analyzer'); |
|
| 129 |
535
|
mapi |
|
|
| 130 |
352
|
mapi |
$this->assertEquals($exptected, $actual); |
|
| 131 |
↓
|
mapi |
} |
|
| 132 |
535
|
mapi |
|
|
| 133 |
352
|
mapi |
/** |
|
| 134 |
535
|
mapi |
* Tests that the logger throws an exception if the log target wasn't |
|
| 135 |
356
|
mapi |
* configured. |
|
| 136 |
↓
|
mapi |
* |
|
| 137 |
↓
|
mapi |
* @return void |
|
| 138 |
↓
|
mapi |
*/ |
|
| 139 |
↓
|
mapi |
public function testThrowsExceptionForInvalidLogTarget() |
|
| 140 |
↓
|
mapi |
{ |
|
| 141 |
↓
|
mapi |
$this->setExpectedException( |
|
| 142 |
↓
|
mapi |
'PHP_Depend_Log_NoLogOutputException', |
|
| 143 |
↓
|
mapi |
"The log target is not configured for 'PHP_Depend_Log_Jdepend_Xml'." |
|
| 144 |
↓
|
mapi |
); |
|
| 145 |
535
|
mapi |
|
|
| 146 |
356
|
mapi |
$logger = new PHP_Depend_Log_Jdepend_Xml(); |
|
| 147 |
↓
|
mapi |
$logger->close(); |
|
| 148 |
↓
|
mapi |
} |
|
| 149 |
535
|
mapi |
|
|
| 150 |
356
|
mapi |
/** |
|
| 151 |
535
|
mapi |
* Tests that {@link PHP_Depend_Log_Summary_Xml::write()} generates the |
|
| 152 |
↓
|
mapi |
* expected document structure for the source, but without any applied |
|
| 153 |
201
|
mapi |
* metrics. |
|
| 154 |
↓
|
mapi |
* |
|
| 155 |
↓
|
mapi |
* @return void |
|
| 156 |
↓
|
mapi |
*/ |
|
| 157 |
↓
|
mapi |
public function testXmlLogWithoutMetrics() |
|
| 158 |
↓
|
mapi |
{ |
|
| 159 |
356
|
mapi |
$log = new PHP_Depend_Log_Jdepend_Xml(); |
|
| 160 |
↓
|
mapi |
$log->setLogFile($this->resultFile); |
|
| 161 |
↓
|
mapi |
$log->setCode($this->packages); |
|
| 162 |
201
|
mapi |
$log->log($this->analyzer); |
|
| 163 |
↓
|
mapi |
$log->close(); |
|
| 164 |
535
|
mapi |
|
|
| 165 |
632
|
mapi |
$fileName = 'pdepend-log' . CORE_PACKAGE . '.xml'; |
|
| 166 |
201
|
mapi |
$this->assertXmlStringEqualsXmlString( |
|
| 167 |
↓
|
mapi |
$this->getNormalizedPathXml(dirname(__FILE__) . "/_expected/{$fileName}"), |
|
| 168 |
↓
|
mapi |
file_get_contents($this->resultFile) |
|
| 169 |
↓
|
mapi |
); |
|
| 170 |
↓
|
mapi |
} |
|
| 171 |
535
|
mapi |
|
|
| 172 |
201
|
mapi |
public function testXmlLogAcceptsOnlyTheCorrectAnalyzer() |
|
| 173 |
↓
|
mapi |
{ |
|
| 174 |
356
|
mapi |
$logger = new PHP_Depend_Log_Jdepend_Xml(); |
|
| 175 |
535
|
mapi |
|
|
| 176 |
201
|
mapi |
$this->assertFalse($logger->log(new PHP_Depend_Log_DummyAnalyzer())); |
|
| 177 |
↓
|
mapi |
$this->assertTrue($logger->log(new PHP_Depend_Metrics_Dependency_Analyzer())); |
|
| 178 |
↓
|
mapi |
} |
|
| 179 |
535
|
mapi |
|
|
| 180 |
201
|
mapi |
/** |
|
| 181 |
↓
|
mapi |
* Normalizes the file references within the expected result document. |
|
| 182 |
↓
|
mapi |
* |
|
| 183 |
↓
|
mapi |
* @param string $fileName File name of the expected result document. |
|
| 184 |
535
|
mapi |
* |
|
| 185 |
201
|
mapi |
* @return string The prepared xml document |
|
| 186 |
↓
|
mapi |
*/ |
|
| 187 |
↓
|
mapi |
protected function getNormalizedPathXml($fileName) |
|
| 188 |
↓
|
mapi |
{ |
|
| 189 |
1027
|
mapi |
$path = realpath(dirname(__FILE__) . '/../../_code/code-5.2.x'); |
|
| 190 |
535
|
mapi |
|
|
| 191 |
1027
|
mapi |
return preg_replace( |
|
| 192 |
↓
|
mapi |
'(sourceFile="[^"]+/([^/"]+)")', |
|
| 193 |
↓
|
mapi |
'sourceFile="' . $path . '/\\1"', |
|
| 194 |
↓
|
mapi |
file_get_contents($fileName) |
|
| 195 |
↓
|
mapi |
); |
|
| 196 |
201
|
mapi |
} |
|
| 197 |
535
|
mapi |
|
|
| 198 |
356
|
mapi |
} |
|