[FEATURE] Add trait to detect public deprecated methods
[Packages/TYPO3.CMS.git] / typo3 / sysext / core / Tests / UnitDeprecated / Compatibility / PublicMethodDeprecationTraitTest.php
1 <?php
2 declare(strict_types = 1);
3 namespace TYPO3\CMS\Core\Tests\UnitDeprecated\Compatibility;
4
5 /*
6 * This file is part of the TYPO3 CMS project.
7 *
8 * It is free software; you can redistribute it and/or modify it under
9 * the terms of the GNU General Public License, either version 2
10 * of the License, or any later version.
11 *
12 * For the full copyright and license information, please read the
13 * LICENSE.txt file that was distributed with this source code.
14 *
15 * The TYPO3 project - inspiring people to share!
16 */
17
18 use TYPO3\CMS\Core\Tests\UnitDeprecated\Compatibility\Fixtures\PublicMethodDeprecationTraitTextFixture;
19 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
20
21 /**
22 * Test case
23 */
24 class PublicMethodDeprecationTraitTest extends UnitTestCase
25 {
26 /**
27 * @test
28 */
29 public function publicMethodCanBeCalled(): void
30 {
31 $this->expectException(\RuntimeException::class);
32 $this->expectExceptionCode(1528822131);
33 (new PublicMethodDeprecationTraitTextFixture())->standardPublicMethod();
34 }
35
36 /**
37 * @test
38 */
39 public function protectedMethodNotHandledByTraitThrowsError(): void
40 {
41 $this->expectException(\Error::class);
42 (new PublicMethodDeprecationTraitTextFixture())->standardProtectedMethod();
43 }
44
45 /**
46 * @test
47 */
48 public function notExistingMethodThrowsError(): void
49 {
50 $this->expectException(\Error::class);
51 (new PublicMethodDeprecationTraitTextFixture())->doesNotExist();
52 }
53
54 /**
55 * @test
56 */
57 public function methodMadeProtectedCanBeCalled(): void
58 {
59 $this->expectException(\RuntimeException::class);
60 $this->expectExceptionCode(1528822485);
61 (new PublicMethodDeprecationTraitTextFixture())->methodMadeProtected();
62 }
63
64 /**
65 * @test
66 */
67 public function methodMadeProtectedReturnsValue(): void
68 {
69 $this->assertEquals('foo', (new PublicMethodDeprecationTraitTextFixture())->methodMadeProtectedWithReturn());
70 }
71
72 /**
73 * @test
74 */
75 public function methodMadeProtectedCanBeCalledWithArguments(): void
76 {
77 $this->expectException(\RuntimeException::class);
78 $this->expectExceptionCode(1528822486);
79 (new PublicMethodDeprecationTraitTextFixture())->methodMadeProtectedWithArguments('foo', 'bar');
80 }
81 }