<commit_before><?php

declare(strict_types=1);

namespace Reinfi\DependencyInjection\Unit\Service\Extractor;

use PHPUnit\Framework\TestCase;
use Prophecy\PhpUnit\ProphecyTrait;
use Reinfi\DependencyInjection\Injection\InjectionInterface;
use Reinfi\DependencyInjection\Service\Extractor\AttributeExtractor;
use Reinfi\DependencyInjection\Test\Service\Service1;
use Reinfi\DependencyInjection\Test\Service\Service2;
use Reinfi\DependencyInjection\Test\Service\ServiceAttribute;
use Reinfi\DependencyInjection\Test\Service\ServiceAttributeConstructor;

class AttributeExtractorTest extends TestCase
{
    use ProphecyTrait;

    /**
     * @test
     */
    public function itResolvesPropertyAnnotations(): void
    {
        $isPhp8OrAbove = version_compare(PHP_VERSION, '8.0.0') >= 0;

        if (!$isPhp8OrAbove) {
            $this->markTestSkipped('Not a php version of 8.0 or above');
        }

        $extractor = new AttributeExtractor();

        $injections = $extractor->getPropertiesInjections(ServiceAttribute::class);

        self::assertCount(3, $injections);
        self::assertContainsOnlyInstancesOf(InjectionInterface::class, $injections);
    }

    /**
     * @test
     */
    public function itResolvesConstructorAnnotations(): void
    {
        $isPhp8OrAbove = version_compare(PHP_VERSION, '8.0.0') >= 0;

        if (!$isPhp8OrAbove) {
            $this->markTestSkipped('Not a php version of 8.0 or above');
        }

        $extractor = new AttributeExtractor();

        $injections = $extractor->getConstructorInjections(ServiceAttributeConstructor::class);

        self::assertCount(1, $injections);
        self::assertContainsOnlyInstancesOf(InjectionInterface::class, $injections);
    }

    /**
     * @test
     */
    public function itReturnsEmptyArrayIfNoConstructorIsDefined(): void
    {
        $extractor = new AttributeExtractor();

        $injections = $extractor->getConstructorInjections(Service2::class);

        self::assertCount(0, $injections);
    }

    /**
     * @test
     */
    public function itReturnsEmptyArrayIfNoConstructorAttributeIsDefined(): void
    {
        $extractor = new AttributeExtractor();

        $injections = $extractor->getConstructorInjections(Service1::class);

        self::assertCount(0, $injections);
    }
}<commit_msg>skip tests which only works on php 8.0<commit_after><?php

declare(strict_types=1);

namespace Reinfi\DependencyInjection\Unit\Service\Extractor;

use PHPUnit\Framework\TestCase;
use Prophecy\PhpUnit\ProphecyTrait;
use Reinfi\DependencyInjection\Injection\InjectionInterface;
use Reinfi\DependencyInjection\Service\Extractor\AttributeExtractor;
use Reinfi\DependencyInjection\Test\Service\Service1;
use Reinfi\DependencyInjection\Test\Service\Service2;
use Reinfi\DependencyInjection\Test\Service\ServiceAttribute;
use Reinfi\DependencyInjection\Test\Service\ServiceAttributeConstructor;

class AttributeExtractorTest extends TestCase
{
    use ProphecyTrait;

    /**
     * @test
     */
    public function itResolvesPropertyAnnotations(): void
    {
        $isPhp8OrAbove = version_compare(PHP_VERSION, '8.0.0') >= 0;

        if (!$isPhp8OrAbove) {
            $this->markTestSkipped('Not a php version of 8.0 or above');
        }

        $extractor = new AttributeExtractor();

        $injections = $extractor->getPropertiesInjections(ServiceAttribute::class);

        self::assertCount(3, $injections);
        self::assertContainsOnlyInstancesOf(InjectionInterface::class, $injections);
    }

    /**
     * @test
     */
    public function itResolvesConstructorAnnotations(): void
    {
        $isPhp8OrAbove = version_compare(PHP_VERSION, '8.0.0') >= 0;

        if (!$isPhp8OrAbove) {
            $this->markTestSkipped('Not a php version of 8.0 or above');
        }

        $extractor = new AttributeExtractor();

        $injections = $extractor->getConstructorInjections(ServiceAttributeConstructor::class);

        self::assertCount(1, $injections);
        self::assertContainsOnlyInstancesOf(InjectionInterface::class, $injections);
    }

    /**
     * @test
     */
    public function itReturnsEmptyArrayIfNoConstructorIsDefined(): void
    {
        $extractor = new AttributeExtractor();

        $injections = $extractor->getConstructorInjections(Service2::class);

        self::assertCount(0, $injections);
    }

    /**
     * @test
     */
    public function itReturnsEmptyArrayIfNoConstructorAttributeIsDefined(): void
    {
        $isPhp8OrAbove = version_compare(PHP_VERSION, '8.0.0') >= 0;

        if (!$isPhp8OrAbove) {
            $this->markTestSkipped('Not a php version of 8.0 or above');
        }

        $extractor = new AttributeExtractor();

        $injections = $extractor->getConstructorInjections(Service1::class);

        self::assertCount(0, $injections);
    }
}
{'fraction_non_alphanumeric': 0.1130829550144449, 'fraction_numerical': 0.012381345439537762, 'mean_word_length': 3.4838112858464383, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7245629', 'n_tokens_mistral': 1449, 'n_tokens_neox': 1410, 'n_words': 233}