Skip to content

Commit

Permalink
Deprecate old namespace (#40)
Browse files Browse the repository at this point in the history
  • Loading branch information
kubawerlos committed Aug 29, 2023
1 parent a12f93a commit 88e9d53
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 2 deletions.
2 changes: 1 addition & 1 deletion composer.json
Expand Up @@ -28,7 +28,7 @@
"psr-4": {
"Tpay\\OpenApi\\": "src/"
},
"files": [
"classmap": [
"src/legacy_classes.php"
]
},
Expand Down
1 change: 1 addition & 0 deletions phpunit.xml
Expand Up @@ -5,6 +5,7 @@
xsi:noNamespaceSchemaLocation='vendor/phpunit/phpunit/phpunit.xsd'
beStrictAboutChangesToGlobalState='true'
beStrictAboutOutputDuringTests='true'
beStrictAboutTestsThatDoNotTestAnything='true'
beStrictAboutTodoAnnotatedTests='true'
bootstrap='./vendor/autoload.php'
cacheResult='false'
Expand Down
1 change: 1 addition & 0 deletions src/legacy_classes.php
@@ -1,6 +1,7 @@
<?php

namespace tpaySDK {
@trigger_error('Using "tpaySDK*" namespace is deprecated and will be removed in 2.0.0', E_USER_DEPRECATED);
class Loader extends \Tpay\OpenApi\Loader {}
}

Expand Down
25 changes: 24 additions & 1 deletion tests/LegacyNamespaceTest.php
@@ -1,14 +1,37 @@
<?php

namespace Tpay\OpenApi\Tests;
namespace Tpay\Tests\OpenApi;

use PHPUnit\Framework\TestCase;
use RuntimeException;

/**
* @coversNothing
*/
class LegacyNamespaceTest extends TestCase
{
/** @runInSeparateProcess */
public function testUsingNewNamespaceDoesNotTriggerDeprecation()
{
$this->addToAssertionCount(1);

new \Tpay\OpenApi\Model\Fields\Person\Name();
}

/** @runInSeparateProcess */
public function testUsingOldNamespaceDoesTriggerDeprecation()
{
set_error_handler(static function ($errno, $errstr) {
restore_error_handler();
throw new RuntimeException($errstr);
}, E_USER_DEPRECATED);

$this->expectException(RuntimeException::class);
$this->expectExceptionMessage('Using "tpaySDK*" namespace is deprecated and will be removed in 2.0.0');

new \tpaySDK\Model\Fields\Person\Name();
}

public function testClassesExist()
{
foreach (self::getLegacyClassNamesFromArray() as $className) {
Expand Down

0 comments on commit 88e9d53

Please sign in to comment.