PageRenderTime 54ms CodeModel.GetById 24ms RepoModel.GetById 0ms app.codeStats 0ms

/src/test/php/PHP/Depend/Code/MethodTest.php

http://github.com/manuelpichler/pdepend
PHP | 848 lines | 444 code | 85 blank | 319 comment | 1 complexity | a8895844e40c079ab3abbbca5331d22a MD5 | raw file
Possible License(s): BSD-3-Clause
  1. <?php
  2. /**
  3. * This file is part of PHP_Depend.
  4. *
  5. * PHP Version 5
  6. *
  7. * Copyright (c) 2008-2012, Manuel Pichler <mapi@pdepend.org>.
  8. * All rights reserved.
  9. *
  10. * Redistribution and use in source and binary forms, with or without
  11. * modification, are permitted provided that the following conditions
  12. * are met:
  13. *
  14. * * Redistributions of source code must retain the above copyright
  15. * notice, this list of conditions and the following disclaimer.
  16. *
  17. * * Redistributions in binary form must reproduce the above copyright
  18. * notice, this list of conditions and the following disclaimer in
  19. * the documentation and/or other materials provided with the
  20. * distribution.
  21. *
  22. * * Neither the name of Manuel Pichler nor the names of his
  23. * contributors may be used to endorse or promote products derived
  24. * from this software without specific prior written permission.
  25. *
  26. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  27. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  28. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  29. * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
  30. * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  31. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
  32. * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  33. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  34. * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  35. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
  36. * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  37. * POSSIBILITY OF SUCH DAMAGE.
  38. *
  39. * @category QualityAssurance
  40. * @package PHP_Depend
  41. * @author Manuel Pichler <mapi@pdepend.org>
  42. * @copyright 2008-2012 Manuel Pichler. All rights reserved.
  43. * @license http://www.opensource.org/licenses/bsd-license.php BSD License
  44. * @version SVN: $Id$
  45. * @link http://pdepend.org/
  46. */
  47. require_once dirname(__FILE__) . '/AbstractItemTest.php';
  48. require_once dirname(__FILE__) . '/../Visitor/TestNodeVisitor.php';
  49. /**
  50. * Test case implementation for the PHP_Depend_Code_Method class.
  51. *
  52. * @category QualityAssurance
  53. * @package PHP_Depend
  54. * @author Manuel Pichler <mapi@pdepend.org>
  55. * @copyright 2008-2012 Manuel Pichler. All rights reserved.
  56. * @license http://www.opensource.org/licenses/bsd-license.php BSD License
  57. * @version Release: @package_version@
  58. * @link http://pdepend.org/
  59. *
  60. * @covers PHP_Depend_Parser
  61. * @covers PHP_Depend_Code_Method
  62. * @covers PHP_Depend_Code_AbstractCallable
  63. * @group pdepend
  64. * @group pdepend::code
  65. * @group unittest
  66. */
  67. class PHP_Depend_Code_MethodTest extends PHP_Depend_Code_AbstractItemTest
  68. {
  69. /**
  70. * testIsCachedReturnsFalseByDefault
  71. *
  72. * @return void
  73. */
  74. public function testIsCachedReturnsFalseByDefault()
  75. {
  76. $method = $this->createItem();
  77. self::assertFalse($method->isCached());
  78. }
  79. /**
  80. * testIsCachedReturnsFalseWhenObjectGetsSerialized
  81. *
  82. * @return void
  83. */
  84. public function testIsCachedReturnsFalseWhenObjectGetsSerialized()
  85. {
  86. $method = $this->createItem();
  87. serialize($method);
  88. self::assertFalse($method->isCached());
  89. }
  90. /**
  91. * testReturnValueOfMagicSleepContainsContextProperty
  92. *
  93. * @return void
  94. */
  95. public function testReturnValueOfMagicSleepContainsContextProperty()
  96. {
  97. $method = new PHP_Depend_Code_Method('method');
  98. self::assertEquals(
  99. array(
  100. 'modifiers',
  101. 'cache',
  102. 'uuid',
  103. 'name',
  104. 'nodes',
  105. 'startLine',
  106. 'endLine',
  107. 'docComment',
  108. 'returnsReference',
  109. 'returnClassReference',
  110. 'exceptionClassReferences'
  111. ),
  112. $method->__sleep()
  113. );
  114. }
  115. /**
  116. * testParserSetsAbstractFlagOnMethod
  117. *
  118. * @return void
  119. */
  120. public function testParserNotSetsAbstractFlagOnMethod()
  121. {
  122. $method = $this->getFirstMethodInClass();
  123. self::assertFalse($method->isAbstract());
  124. }
  125. /**
  126. * testParserSetsAbstractFlagOnMethod
  127. *
  128. * @return void
  129. */
  130. public function testParserSetsAbstractFlagOnMethod()
  131. {
  132. $method = $this->getFirstMethodInClass();
  133. self::assertTrue($method->isAbstract());
  134. }
  135. /**
  136. * testGetReturnClassForMethodWithNamespacedRootClass
  137. *
  138. * @return void
  139. */
  140. public function testGetReturnClassForMethodWithNamespacedRootClass()
  141. {
  142. $method = $this->getFirstMethodInClass();
  143. self::assertEquals('Foo', $method->getReturnClass()->getName());
  144. }
  145. /**
  146. * testGetReturnClassForMethodWithNamespacedClass
  147. *
  148. * @return void
  149. */
  150. public function testGetReturnClassForMethodWithNamespacedClass()
  151. {
  152. $method = $this->getFirstMethodInClass();
  153. self::assertEquals('Baz', $method->getReturnClass()->getName());
  154. }
  155. /**
  156. * testGetReturnClassForMethodWithNamespacedArrayRootClass
  157. *
  158. * @return void
  159. */
  160. public function testGetReturnClassForMethodWithNamespacedArrayRootClass()
  161. {
  162. $method = $this->getFirstMethodInClass();
  163. self::assertEquals('Foo', $method->getReturnClass()->getName());
  164. }
  165. /**
  166. * testGetReturnClassForMethodWithNamespacedArrayClass
  167. *
  168. * @return void
  169. */
  170. public function testGetReturnClassForMethodWithNamespacedArrayClass()
  171. {
  172. $method = $this->getFirstMethodInClass();
  173. self::assertEquals('Baz', $method->getReturnClass()->getName());
  174. }
  175. /**
  176. * testGetExceptionsForMethodWithNamespacedRootClass
  177. *
  178. * @return void
  179. */
  180. public function testGetExceptionsForMethodWithNamespacedRootClass()
  181. {
  182. $method = $this->getFirstMethodInClass();
  183. self::assertEquals(
  184. 'Exception',
  185. $method->getExceptionClasses()->current()->getName()
  186. );
  187. }
  188. /**
  189. * testGetExceptionsForMethodWithNamespacedClass
  190. *
  191. * @return void
  192. */
  193. public function testGetExceptionsForMethodWithNamespacedClass()
  194. {
  195. $method = $this->getFirstMethodInClass();
  196. self::assertEquals(
  197. 'ErrorException',
  198. $method->getExceptionClasses()->current()->getName()
  199. );
  200. }
  201. /**
  202. * testInlineDependencyForMethodWithNamespacedRootClass
  203. *
  204. * @return void
  205. */
  206. public function testInlineDependencyForMethodWithNamespacedRootClass()
  207. {
  208. $method = $this->getFirstMethodInClass();
  209. self::assertEquals(
  210. 'ASTBuilder',
  211. $method->getDependencies()->current()->getName()
  212. );
  213. }
  214. /**
  215. * testInlineDependencyForMethodWithNamespacedClass
  216. *
  217. * @return void
  218. */
  219. public function testInlineDependencyForMethodWithNamespacedClass()
  220. {
  221. $method = $this->getFirstMethodInClass();
  222. self::assertEquals(
  223. 'ASTBuilder',
  224. $method->getDependencies()->current()->getName()
  225. );
  226. }
  227. /**
  228. * testReturnsReferenceReturnsExpectedTrue
  229. *
  230. * @return void
  231. */
  232. public function testReturnsReferenceReturnsExpectedTrue()
  233. {
  234. $method = $this->getFirstMethodInClass();
  235. self::assertTrue($method->returnsReference());
  236. }
  237. /**
  238. * testReturnsReferenceReturnsExpectedFalse
  239. *
  240. * @return void
  241. */
  242. public function testReturnsReferenceReturnsExpectedFalse()
  243. {
  244. $method = $this->getFirstMethodInClass();
  245. self::assertFalse($method->returnsReference());
  246. }
  247. /**
  248. * testGetStaticVariablesReturnsEmptyArrayByDefault
  249. *
  250. * @return void
  251. */
  252. public function testGetStaticVariablesReturnsEmptyArrayByDefault()
  253. {
  254. $method = new PHP_Depend_Code_Method('method');
  255. self::assertEquals(array(), $method->getStaticVariables());
  256. }
  257. /**
  258. * testGetStaticVariablesReturnsFirstSetOfStaticVariables
  259. *
  260. * @return void
  261. */
  262. public function testGetStaticVariablesReturnsFirstSetOfStaticVariables()
  263. {
  264. $method = $this->getFirstMethodInClass();
  265. self::assertEquals(
  266. array('a' => 42, 'b' => 23),
  267. $method->getStaticVariables()
  268. );
  269. }
  270. /**
  271. * testGetStaticVariablesReturnsMergeOfAllStaticVariables
  272. *
  273. * @return void
  274. */
  275. public function testGetStaticVariablesReturnsMergeOfAllStaticVariables()
  276. {
  277. $method = $this->getFirstMethodInClass();
  278. self::assertEquals(
  279. array('a' => 42, 'b' => 23, 'c' => 17),
  280. $method->getStaticVariables()
  281. );
  282. }
  283. /**
  284. * testGetSourceFileThrowsExpectedExceptionWhenNoParentWasDefined
  285. *
  286. * @return void
  287. * @covers PHP_Depend_Code_Exceptions_AbstractException
  288. * @covers PHP_Depend_Code_Exceptions_SourceNotFoundException
  289. * @expectedException PHP_Depend_Code_Exceptions_SourceNotFoundException
  290. */
  291. public function testGetSourceFileThrowsExpectedExceptionWhenNoParentWasDefined()
  292. {
  293. $method = new PHP_Depend_Code_Method('method');
  294. $method->getSourceFile();
  295. }
  296. /**
  297. * Tests that build interface updates the source file information for null
  298. * values.
  299. *
  300. * @return void
  301. */
  302. public function testSetSourceFileInformationForNullValue()
  303. {
  304. $file = new PHP_Depend_Code_File(__FILE__);
  305. $class = new PHP_Depend_Code_Class(__CLASS__);
  306. $class->setSourceFile($file);
  307. $method = new PHP_Depend_Code_Method(__FUNCTION__);
  308. $method->setParent($class);
  309. self::assertSame($file, $method->getSourceFile());
  310. }
  311. /**
  312. * Tests that the build interface method doesn't update an existing source
  313. * file info.
  314. *
  315. * @return void
  316. */
  317. public function testDoesntSetSourceFileInformationForNotNullValue()
  318. {
  319. $this->markTestSkipped(
  320. 'This test should be removed, but a default implementation exists.'
  321. );
  322. }
  323. /**
  324. * testByDefaultGetParentReturnsNull
  325. *
  326. * @return void
  327. */
  328. public function testByDefaultGetParentReturnsNull()
  329. {
  330. $method = new PHP_Depend_Code_Method('method');
  331. self::assertNull($method->getParent());
  332. }
  333. /**
  334. * testSetParentWithNullResetsPreviousParentToNull
  335. *
  336. * @return void
  337. */
  338. public function testSetParentWithNullResetsPreviousParentToNull()
  339. {
  340. $class = new PHP_Depend_Code_Class('clazz', 0, 'clazz.php');
  341. $method = new PHP_Depend_Code_Method('method');
  342. $method->setParent($class);
  343. $method->setParent(null);
  344. self::assertNull($method->getParent());
  345. }
  346. /**
  347. * Tests that the {@link PHP_Depend_Code_Method::getParent()} returns as
  348. * default value <b>null</b> and that the package could be set and unset.
  349. *
  350. * @return void
  351. */
  352. public function testGetSetParent()
  353. {
  354. $class = new PHP_Depend_Code_Class('clazz', 0, 'clazz.php');
  355. $method = new PHP_Depend_Code_Method('method');
  356. $method->setParent($class);
  357. self::assertSame($class, $method->getParent());
  358. }
  359. /**
  360. * Tests the visitor accept method.
  361. *
  362. * @return void
  363. */
  364. public function testVisitorAccept()
  365. {
  366. $method = new PHP_Depend_Code_Method('method', 0);
  367. $visitor = new PHP_Depend_Visitor_TestNodeVisitor();
  368. $method->accept($visitor);
  369. self::assertSame($method, $visitor->method);
  370. }
  371. /**
  372. * Tests that the {@link PHP_Depend_Code_Method::setModifiers()} method
  373. * fails with an exception for an invalid modifier value.
  374. *
  375. * @return void
  376. */
  377. public function testSetInvalidModifierFail()
  378. {
  379. $this->setExpectedException('InvalidArgumentException');
  380. $method = new PHP_Depend_Code_Method('method');
  381. $method->setModifiers(-1);
  382. }
  383. /**
  384. * Tests that the {@link PHP_Depend_Code_Method::setModifiers()} method
  385. * accepts the defined visibility value.
  386. *
  387. * @return void
  388. */
  389. public function testSetModifiersAcceptsPublicValue()
  390. {
  391. $method = new PHP_Depend_Code_Method('method');
  392. $method->setModifiers(PHP_Depend_ConstantsI::IS_PUBLIC);
  393. self::assertTrue(
  394. $method->isPublic() &&
  395. !$method->isProtected() &&
  396. !$method->isPrivate()
  397. );
  398. }
  399. /**
  400. * testGetModifiersReturnsZeroByDefault
  401. *
  402. * @return void
  403. * @since 1.0.0
  404. */
  405. public function testGetModifiersReturnsZeroByDefault()
  406. {
  407. $method = new PHP_Depend_Code_Method('method');
  408. $this->assertSame(0, $method->getModifiers());
  409. }
  410. /**
  411. * testGetModifiersReturnsPreviousSetValue
  412. *
  413. * @return void
  414. * @since 1.0.0
  415. */
  416. public function testGetModifiersReturnsPreviousSetValue()
  417. {
  418. $method = new PHP_Depend_Code_Method('method');
  419. $method->setModifiers(PHP_Depend_ConstantsI::IS_ABSTRACT);
  420. $this->assertEquals(
  421. PHP_Depend_ConstantsI::IS_ABSTRACT,
  422. $method->getModifiers()
  423. );
  424. }
  425. /**
  426. * testIsStaticDefaultByReturnsFalse
  427. *
  428. * @return void
  429. */
  430. public function testIsStaticDefaultByReturnsFalse()
  431. {
  432. $method = new PHP_Depend_Code_Method('method');
  433. self::assertFalse($method->isStatic());
  434. }
  435. /**
  436. * Tests that the {@link PHP_Depend_Code_Method::setModifiers()} method marks
  437. * a method as static.
  438. *
  439. * @return void
  440. */
  441. public function testSetModifiersMarksMethodAsStatic()
  442. {
  443. $method = new PHP_Depend_Code_Method('method');
  444. $method->setModifiers(
  445. PHP_Depend_ConstantsI::IS_PROTECTED |
  446. PHP_Depend_ConstantsI::IS_STATIC
  447. );
  448. self::assertTrue($method->isStatic());
  449. }
  450. /**
  451. * testIsFinalByDefaultReturnsFalse
  452. *
  453. * @return void
  454. */
  455. public function testIsFinalByDefaultReturnsFalse()
  456. {
  457. $method = new PHP_Depend_Code_Method('method');
  458. self::assertFalse($method->isFinal());
  459. }
  460. /**
  461. * Tests that the {@link PHP_Depend_Code_Method::setModifiers()} method marks
  462. * a method as final.
  463. *
  464. * @return void
  465. */
  466. public function testSetModifiersMarksMethodAsFinal()
  467. {
  468. $method = new PHP_Depend_Code_Method('method');
  469. $method->setModifiers(
  470. PHP_Depend_ConstantsI::IS_PROTECTED |
  471. PHP_Depend_ConstantsI::IS_FINAL
  472. );
  473. self::assertTrue($method->isFinal());
  474. }
  475. /**
  476. * Tests that the {@link PHP_Depend_Code_Method::setModifiers()} method marks
  477. * a method as static+final.
  478. *
  479. * @return void
  480. */
  481. public function testSetModifiersMarksMethodAsStaticFinal()
  482. {
  483. $method = new PHP_Depend_Code_Method('method');
  484. $method->setModifiers(
  485. PHP_Depend_ConstantsI::IS_PROTECTED |
  486. PHP_Depend_ConstantsI::IS_STATIC |
  487. PHP_Depend_ConstantsI::IS_FINAL
  488. );
  489. self::assertTrue($method->isFinal() && $method->isStatic());
  490. }
  491. /**
  492. * Tests that the {@link PHP_Depend_Code_Method::setModifiers()} method
  493. * accepts the defined visibility value.
  494. *
  495. * @return void
  496. */
  497. public function testSetModifiersAcceptsProtectedValue()
  498. {
  499. $method = new PHP_Depend_Code_Method('method');
  500. $method->setModifiers(PHP_Depend_ConstantsI::IS_PROTECTED);
  501. self::assertTrue(
  502. $method->isProtected() &&
  503. !$method->isPublic() &&
  504. !$method->isPrivate()
  505. );
  506. }
  507. /**
  508. * Tests that the {@link PHP_Depend_Code_Method::setModifiers()} method
  509. * accepts the defined visibility value.
  510. *
  511. * @return void
  512. */
  513. public function testSetModifiersAcceptsPrivateValue()
  514. {
  515. $method = new PHP_Depend_Code_Method('method');
  516. $method->setModifiers(PHP_Depend_ConstantsI::IS_PRIVATE);
  517. self::assertTrue(
  518. $method->isPrivate() &&
  519. !$method->isPublic() &&
  520. !$method->isProtected()
  521. );
  522. }
  523. /**
  524. * testIsPublicByDefaultReturnsFalse
  525. *
  526. * @return void
  527. */
  528. public function testIsPublicByDefaultReturnsFalse()
  529. {
  530. $method = new PHP_Depend_Code_Method('method');
  531. self::assertFalse($method->isPublic());
  532. }
  533. /**
  534. * Tests the behavior of {@link PHP_Depend_Code_Method::getFirstChildOfType()}.
  535. *
  536. * @return void
  537. */
  538. public function testGetFirstChildOfTypeReturnsTheExpectedFirstMatch()
  539. {
  540. $node1 = $this->getMock(
  541. 'PHP_Depend_Code_ASTNodeI',
  542. array(),
  543. array(),
  544. 'PHP_Depend_Code_ASTNodeI_' . md5(microtime())
  545. );
  546. $node1->expects($this->once())
  547. ->method('getFirstChildOfType')
  548. ->will($this->returnValue(null));
  549. $node2 = $this->getMock(
  550. 'PHP_Depend_Code_ASTNodeI',
  551. array(),
  552. array(),
  553. 'PHP_Depend_Code_ASTNodeI_' . md5(microtime())
  554. );
  555. $node2->expects($this->never())
  556. ->method('getFirstChildOfType')
  557. ->will($this->returnValue(null));
  558. $method = new PHP_Depend_Code_Method('Method');
  559. $method->addChild($node1);
  560. $method->addChild($node2);
  561. $child = $method->getFirstChildOfType(get_class($node2));
  562. self::assertSame($node2, $child);
  563. }
  564. /**
  565. * Tests the behavior of {@link PHP_Depend_Code_Method::getFirstChildOfType()}.
  566. *
  567. * @return void
  568. */
  569. public function testGetFirstChildOfTypeReturnsTheExpectedNestedMatch()
  570. {
  571. $node1 = $this->getMock(
  572. 'PHP_Depend_Code_ASTNodeI',
  573. array(),
  574. array(),
  575. 'PHP_Depend_Code_ASTNodeI_' . md5(microtime())
  576. );
  577. $node1->expects($this->never())
  578. ->method('getFirstChildOfType');
  579. $node2 = $this->getMock(
  580. 'PHP_Depend_Code_ASTNodeI',
  581. array(),
  582. array(),
  583. 'PHP_Depend_Code_ASTNodeI_' . md5(microtime())
  584. );
  585. $node2->expects($this->once())
  586. ->method('getFirstChildOfType')
  587. ->will($this->returnValue(null));
  588. $node3 = $this->getMock(
  589. 'PHP_Depend_Code_ASTNodeI',
  590. array(),
  591. array(),
  592. 'PHP_Depend_Code_ASTNodeI_' . md5(microtime())
  593. );
  594. $node3->expects($this->once())
  595. ->method('getFirstChildOfType')
  596. ->will($this->returnValue($node1));
  597. $method = new PHP_Depend_Code_Method('Method');
  598. $method->addChild($node2);
  599. $method->addChild($node3);
  600. $child = $method->getFirstChildOfType(get_class($node1));
  601. self::assertSame($node1, $child);
  602. }
  603. /**
  604. * Tests the behavior of {@link PHP_Depend_Code_Method::getFirstChildOfType()}.
  605. *
  606. * @return void
  607. */
  608. public function testGetFirstChildOfTypeReturnsTheExpectedNull()
  609. {
  610. $node1 = $this->getMock(
  611. 'PHP_Depend_Code_ASTNodeI',
  612. array(),
  613. array(),
  614. 'PHP_Depend_Code_ASTNodeI_' . md5(microtime())
  615. );
  616. $node1->expects($this->once())
  617. ->method('getFirstChildOfType')
  618. ->will($this->returnValue(null));
  619. $node2 = $this->getMock(
  620. 'PHP_Depend_Code_ASTNodeI',
  621. array(),
  622. array(),
  623. 'PHP_Depend_Code_ASTNodeI_' . md5(microtime())
  624. );
  625. $node2->expects($this->once())
  626. ->method('getFirstChildOfType')
  627. ->will($this->returnValue(null));
  628. $method = new PHP_Depend_Code_Method('Method');
  629. $method->addChild($node1);
  630. $method->addChild($node2);
  631. $child = $method->getFirstChildOfType(
  632. 'PHP_Depend_Code_ASTNodeI_' . md5(microtime())
  633. );
  634. self::assertNull($child);
  635. }
  636. /**
  637. * Tests the behavior of {@link PHP_Depend_Code_Method::findChildrenOfType()}.
  638. *
  639. * @return void
  640. */
  641. public function testFindChildrenOfTypeReturnsExpectedResult()
  642. {
  643. $node1 = $this->getMock(
  644. 'PHP_Depend_Code_ASTNodeI',
  645. array(),
  646. array(),
  647. 'PHP_Depend_Code_ASTNodeI_' . md5(microtime())
  648. );
  649. $node1->expects($this->once())
  650. ->method('findChildrenOfType')
  651. ->will($this->returnValue(array()));
  652. $node2 = $this->getMock(
  653. 'PHP_Depend_Code_ASTNodeI',
  654. array(),
  655. array(),
  656. 'PHP_Depend_Code_ASTNodeI_' . md5(microtime())
  657. );
  658. $node2->expects($this->once())
  659. ->method('findChildrenOfType')
  660. ->will($this->returnValue(array()));
  661. $method = new PHP_Depend_Code_Method('Method');
  662. $method->addChild($node1);
  663. $method->addChild($node2);
  664. $children = $method->findChildrenOfType(get_class($node2));
  665. self::assertSame(array($node2), $children);
  666. }
  667. /**
  668. * testUnserializedMethodStillReferencesSameDependency
  669. *
  670. * @return void
  671. */
  672. public function testUnserializedMethodStillReferencesSameDependency()
  673. {
  674. $orig = $this->getFirstMethodInClass();
  675. $copy = unserialize(serialize($orig));
  676. self::assertSame(
  677. $orig->getDependencies()->current(),
  678. $copy->getDependencies()->current()
  679. );
  680. }
  681. /**
  682. * testUnserializedMethodStillReferencesSameReturnClass
  683. *
  684. * @return void
  685. */
  686. public function testUnserializedMethodStillReferencesSameReturnClass()
  687. {
  688. $orig = $this->getFirstMethodInClass();
  689. $copy = unserialize(serialize($orig));
  690. self::assertSame(
  691. $orig->getReturnClass(),
  692. $copy->getReturnClass()
  693. );
  694. }
  695. /**
  696. * testUnserializedMethodStillReferencesSameParameterClass
  697. *
  698. * @return void
  699. */
  700. public function testUnserializedMethodStillReferencesSameParameterClass()
  701. {
  702. $orig = $this->getFirstMethodInClass();
  703. $copy = unserialize(serialize($orig));
  704. self::assertSame(
  705. $orig->getDependencies()->current(),
  706. $copy->getDependencies()->current()
  707. );
  708. }
  709. /**
  710. * testUnserializedMethodStillReferencesSameExceptionClass
  711. *
  712. * @return void
  713. */
  714. public function testUnserializedMethodStillReferencesSameExceptionClass()
  715. {
  716. $orig = $this->getFirstMethodInClass();
  717. $copy = unserialize(serialize($orig));
  718. self::assertSame(
  719. $orig->getExceptionClasses()->current(),
  720. $copy->getExceptionClasses()->current()
  721. );
  722. }
  723. /**
  724. * testUnserializedMethodStillReferencesSameDependencyInterface
  725. *
  726. * @return void
  727. */
  728. public function testUnserializedMethodStillReferencesSameDependencyInterface()
  729. {
  730. $orig = $this->getFirstMethodInClass();
  731. $copy = unserialize(serialize($orig));
  732. self::assertSame(
  733. $orig->getDependencies()->current(),
  734. $copy->getDependencies()->current()
  735. );
  736. }
  737. /**
  738. * Returns the first method defined in a source file associated with the
  739. * given test case.
  740. *
  741. * @return PHP_Depend_Code_Method
  742. */
  743. protected function getFirstMethodInClass()
  744. {
  745. return self::parseCodeResourceForTest()
  746. ->current()
  747. ->getTypes()
  748. ->current()
  749. ->getMethods()
  750. ->current();
  751. }
  752. /**
  753. * Creates an abstract item instance.
  754. *
  755. * @return PHP_Depend_Code_AbstractItem
  756. */
  757. protected function createItem()
  758. {
  759. $method = new PHP_Depend_Code_Method('method');
  760. $method->setSourceFile(new PHP_Depend_Code_File(__FILE__));
  761. return $method;
  762. }
  763. }