Skip to content

Commit

Permalink
[#ests] - annotations tests for phpunit
Browse files Browse the repository at this point in the history
  • Loading branch information
niden committed Feb 13, 2024
1 parent 553300e commit 1db0f3c
Show file tree
Hide file tree
Showing 50 changed files with 1,407 additions and 868 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php

declare(strict_types=1);

/**
* This file is part of the Phalcon Framework.
*
* (c) Phalcon Team <team@phalcon.io>
*
* For the full copyright and license information, please view the LICENSE.txt
* file that was distributed with this source code.
*/

namespace MyLibrary\Tests\support\data\fixtures\Annotations\Adapter;

use Phalcon\Annotations\Adapter\Stream;

class StreamEmptyDataFixture extends Stream
{
/**
* @param string $filename
*
* @return bool
*
* @link https://php.net/manual/en/function.file-exists.php
*/
protected function phpFileExists(string $filename)
{
return true;
}

/**
* @param string $filename
*
* @return string|false
*
* @link https://php.net/manual/en/function.file-get-contents.php
*/
protected function phpFileGetContents(string $filename)
{
return '';
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

declare(strict_types=1);

/**
* This file is part of the Phalcon Framework.
*
* (c) Phalcon Team <team@phalcon.io>
*
* For the full copyright and license information, please view the LICENSE.txt
* file that was distributed with this source code.
*/

namespace Phalcon\Tests1\Fixtures\Annotations\Adapter;

use Phalcon\Annotations\Adapter\Stream;

class StreamFileExistsFixture extends Stream
{
/**
* @param string $filename
*
* @return bool
*
* @link https://php.net/manual/en/function.file-exists.php
*/
protected function phpFileExists(string $filename)
{
return false;
}
}
38 changes: 38 additions & 0 deletions tests/support/data/fixtures/Annotations/Adapter/StreamFixture.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php

declare(strict_types=1);

/**
* This file is part of the Phalcon Framework.
*
* (c) Phalcon Team <team@phalcon.io>
*
* For the full copyright and license information, please view the LICENSE.txt
* file that was distributed with this source code.
*/

namespace Phalcon\Tests1\Fixtures\Annotations\Adapter;

use Phalcon\Annotations\Adapter\Stream;

class StreamFixture extends Stream
{
/**
* @param string $filename
* @param mixed $data
* @param int $flags
* @param resource $context
*
* @return int|false
*
* @link https://php.net/manual/en/function.file-put-contents.php
*/
protected function phpFilePutContents(
string $filename,
$data,
int $flags = 0,
$context = null
) {
return false;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php

declare(strict_types=1);

/**
* This file is part of the Phalcon Framework.
*
* (c) Phalcon Team <team@phalcon.io>
*
* For the full copyright and license information, please view the LICENSE.txt
* file that was distributed with this source code.
*/

namespace MyLibrary\Tests\support\data\fixtures\Annotations\Adapter;

use Phalcon\Annotations\Adapter\Stream;

class StreamWrongDataFixture extends Stream
{
/**
* @param string $filename
*
* @return bool
*
* @link https://php.net/manual/en/function.file-exists.php
*/
protected function phpFileExists(string $filename)
{
return true;
}

/**
* @param string $filename
*
* @return string|false
*
* @link https://php.net/manual/en/function.file-get-contents.php
*/
protected function phpFileGetContents(string $filename)
{
return '{a:1';
}
}
125 changes: 125 additions & 0 deletions tests/support/data/fixtures/Annotations/TestClass.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
<?php

declare(strict_types=1);

/**
* This file is part of the Phalcon Framework.
*
* (c) Phalcon Team <team@phalcon.io>
*
* For the full copyright and license information, please view the LICENSE.txt
* file that was distributed with this source code.
*/

/**
* TestClass
*
* This is a test class, it's useful to make tests
*
* @Simple
* @SingleParam("Param")
* @MultipleParams("First", Second, 1, 1.1, -10, false, true, null)
* @Params({"key1", "key2", "key3"});
* @HashParams({"key1": "value", "key2": "value", "key3": "value"});
* @NamedParams(first=some, second=other);
* @AlternativeNamedParams(first: some, second: other);
* @AlternativeHashParams({key1="value", "key2"=value, "key3"="value"});
* @RecursiveHash({key1="value", "key2"=value, "key3"=[1, 2, 3, 4]});
*/
class TestClass
{
/**
* @Simple
*/
const TEST_CONST1 = 'test-const-with-annotation';

const TEST_CONST2 = 'test-const-without-annotation';

/**
* This is a property string
*
* @var string
* @Simple
* @SingleParam("Param")
* @MultipleParams("First", Second, 1, 1.1, -10, false, true, null)
*/
public $testProp1;

/**
*
*/
public $testProp2;

/**
* @Simple @SingleParam("Param") @MultipleParams("First", Second, 1, 1.1,
* -10, false, true, null)
*/
public $testProp3;

/**
* @Simple @SingleParam(
* "Param") @MultipleParams( "First",
* Second, 1, 1.1
* ,-10,
* false, true,
* null)
*/
public $testProp4;

public $testProp5;

/**
* This is a comment
*/
public $testProp6;

/**
* This is a property string
*
* @return string
* @Simple
* @SingleParam("Param")
* @MultipleParams("First", Second, 1, 1.1, -10, false, true, null)
* @NamedMultipleParams(first: "First", second: Second)
*/
public function testMethod1()
{
}

/**
*
*/
public function testMethod2()
{
}

/**
* @Simple @SingleParam("Param") @MultipleParams("First", Second, 1, 1.1,
* -10, false, true, null)
*/
public function testMethod3()
{
}

/**
* @Simple @SingleParam(
* "Param") @MultipleParams( "First",
* Second, 1, 1.1
* ,-10,
* false, true,
* null)
*/
public function testMethod4()
{
}

/** @Simple a good comment between annotations @SingleParam(
* "Param") this is extra content @MultipleParams( "First",
* Second, 1, 1.1 ,-10,
* false, true,
* null) more content here
*/
public function testMethod5()
{
}
}
33 changes: 33 additions & 0 deletions tests/support/data/fixtures/Annotations/TestClassNs.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

/**
* This file is part of the Phalcon Framework.
*
* (c) Phalcon Team <team@phalcon.io>
*
* For the full copyright and license information, please view the LICENSE.txt
* file that was distributed with this source code.
*/

declare(strict_types=1);

namespace User;

/**
* User\TestClassNs
*
* This class has annotations but it's in a namespace
*
* @Simple
* @SingleParam("Param")
* @MultipleParams("First", Second, 1, 1.1, -10, false, true, null)
* @Params({"key1", "key2", "key3"});
* @HashParams({"key1": "value", "key2": "value", "key3": "value"});
* @NamedParams(first=some, second=other);
* @AlternativeNamedParams(first: some, second: other);
* @AlternativeHashParams({key1="value", "key2"=value, "key3"="value"});
* @RecursiveHash({key1="value", "key2"=value, "key3"=[1, 2, 3, 4]});
*/
class TestClassNs
{
}
19 changes: 19 additions & 0 deletions tests/support/data/fixtures/Annotations/TestInvalid.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

declare(strict_types=1);

/**
* This file is part of the Phalcon Framework.
*
* (c) Phalcon Team <team@phalcon.io>
*
* For the full copyright and license information, please view the LICENSE.txt
* file that was distributed with this source code.
*/

/**
* @Invalid(
*/
class TestInvalid
{
}
47 changes: 47 additions & 0 deletions tests/support/data/fixtures/Traits/AnnotationsTrait2.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?php

/**
* This file is part of the Phalcon Framework.
*
* (c) Phalcon Team <team@phalcon.io>
*
* For the full copyright and license information, please view the LICENSE.txt
* file that was distributed with this source code.
*/

declare(strict_types=1);

namespace Phalcon\Tests1\Fixtures\Traits;

use Phalcon\Annotations\Adapter\Apcu;
use Phalcon\Annotations\Adapter\Memory;
use Phalcon\Annotations\Adapter\Stream;

use function outputDir;
use function outputDir2;

trait AnnotationsTrait2
{
public static function providerExamples(): array
{
return [
[
Apcu::class,
[
'prefix' => 'nova_prefix',
'lifetime' => 3600,
],
],
[
Memory::class,
[],
],
[
Stream::class,
[
'annotationsDir' => outputDir2('annotations/'),
],
],
];
}
}
2 changes: 1 addition & 1 deletion tests/unit/Acl/Adapter/Memory/AddRoleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ public function testAclAdapterMemoryAddRoleException(): void
{
$this->expectException(Exception::class);
$this->expectExceptionMessage(
'Role must be either a string or implement RoleInterface'
'Role must be either a string or implement RoleInterface'
);

$acl = new Memory();
Expand Down
Loading

0 comments on commit 1db0f3c

Please sign in to comment.