<commit_before><?php
namespace DrdPlus\Tests\ProfessionLevels;

use DrdPlus\Properties\Base\Agility;
use DrdPlus\Properties\Base\Charisma;
use DrdPlus\Properties\Base\Intelligence;
use DrdPlus\Properties\Base\Knack;
use DrdPlus\Properties\Base\Strength;
use DrdPlus\Properties\Base\Will;
use DrdPlus\ProfessionLevels\LevelRank;
use DrdPlus\ProfessionLevels\ProfessionLevel;
use \DrdPlus\Professions\AbstractProfession;
use DrdPlus\Properties\PropertyInterface;
use DrdPlus\Tools\Tests\TestWithMockery;
use Mockery\MockInterface;

abstract class AbstractTestOfProfessionLevel extends TestWithMockery
{

    /**
     * @return ProfessionLevel
     *
     * @test
     */
    public function I_can_create_first_level()
    {
        $professionLevelClass = $this->getProfessionLevelClass();
        $instance = new $professionLevelClass(
            $this->createProfession(),
            $this->createFirstLevelRank(),
            $this->createFirstLevelStrength(),
            $this->createFirstLevelAgility(),
            $this->createFirstLevelKnack(),
            $this->createFirstLevelWill(),
            $this->createFirstLevelIntelligence(),
            $this->createFirstLevelCharisma()
        );
        $this->assertInstanceOf($this->getProfessionLevelClass(), $instance);
        /** @var ProfessionLevel $instance */
        $this->assertNull($instance->getId());
        $this->assertSame($this->getProfessionCode(), $instance->getProfession()->getCode());

        return $instance;
    }

    /** @return LevelRank */
    private function createFirstLevelRank()
    {
        /** @var LevelRank|\Mockery\MockInterface $levelRank */
        $levelRank = \Mockery::mock(LevelRank::class);
        $levelRank->shouldReceive('getValue')
            ->andReturn(1);

        return $levelRank;
    }

    /** @return Strength */
    private function createFirstLevelStrength()
    {
        return $this->createFirstLevelProperty(Strength::class, Strength::STRENGTH);
    }

    /**
     * @param string $propertyClass
     * @param string $propertyCode
     * @return MockInterface|PropertyInterface
     */
    private function createFirstLevelProperty($propertyClass, $propertyCode)
    {
        $property = \Mockery::mock($propertyClass);
        $this->addPropertyFirstLevelExpectation($property, $propertyCode);

        return $property;
    }

    private function addPropertyFirstLevelExpectation(MockInterface $property, $propertyName)
    {
        $property->shouldReceive('getValue')
            ->atLeast()->once()
            ->andReturn($this->isPrimaryProperty($propertyName) ? 1 : 0);
        $property->shouldReceive('getCode')<commit_msg>Fixed tests with first level rank<commit_after><?php
namespace DrdPlus\Tests\ProfessionLevels;

use DrdPlus\Properties\Base\Agility;
use DrdPlus\Properties\Base\Charisma;
use DrdPlus\Properties\Base\Intelligence;
use DrdPlus\Properties\Base\Knack;
use DrdPlus\Properties\Base\Strength;
use DrdPlus\Properties\Base\Will;
use DrdPlus\ProfessionLevels\LevelRank;
use DrdPlus\ProfessionLevels\ProfessionLevel;
use \DrdPlus\Professions\AbstractProfession;
use DrdPlus\Properties\PropertyInterface;
use DrdPlus\Tools\Tests\TestWithMockery;
use Mockery\MockInterface;

abstract class AbstractTestOfProfessionLevel extends TestWithMockery
{

    /**
     * @return ProfessionLevel
     *
     * @test
     */
    public function I_can_create_first_level()
    {
        $professionLevelClass = $this->getProfessionLevelClass();
        $instance = new $professionLevelClass(
            $this->createProfession(),
            $this->createFirstLevelRank(),
            $this->createFirstLevelStrength(),
            $this->createFirstLevelAgility(),
            $this->createFirstLevelKnack(),
            $this->createFirstLevelWill(),
            $this->createFirstLevelIntelligence(),
            $this->createFirstLevelCharisma()
        );
        $this->assertInstanceOf($this->getProfessionLevelClass(), $instance);
        /** @var ProfessionLevel $instance */
        $this->assertNull($instance->getId());
        $this->assertSame($this->getProfessionCode(), $instance->getProfession()->getCode());

        return $instance;
    }

    /** @return LevelRank */
    private function createFirstLevelRank()
    {
        /** @var LevelRank|\Mockery\MockInterface $levelRank */
        $levelRank = \Mockery::mock(LevelRank::class);
        $levelRank->shouldReceive('getValue')
            ->andReturn(1);
        $levelRank->shouldReceive('isFirstLevel')
            ->andReturn(true);

        return $levelRank;
    }

    /** @return Strength */
    private function createFirstLevelStrength()
    {
        return $this->createFirstLevelProperty(Strength::class, Strength::STRENGTH);
    }

    /**
     * @param string $propertyClass
     * @param string $propertyCode
     * @return MockInterface|PropertyInterface
     */
    private function createFirstLevelProperty($propertyClass, $propertyCode)
    {
        $property = \Mockery::mock($propertyClass);
        $this->addPropertyFirstLevelExpectation($property, $propertyCode);

        return $property;
    }

    private function addPropertyFirstLevelExpectation(MockInterface $property, $propertyName)
    {
        $property->shouldReceive('getValue')
            ->atLeast()->once()
            ->andReturn($this->isPrimaryProperty($propertyName) ? 1 : 0);
        $property->shouldReceive('getCode')
{'fraction_non_alphanumeric': 0.12281669424526567, 'fraction_numerical': 0.0011031439602868175, 'mean_word_length': 3.283464566929134, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 59, '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': '4115925', 'n_tokens_mistral': 1548, 'n_tokens_neox': 1478, 'n_words': 230}