<commit_before><?php

namespace PhpAbac\Test;

use PhpAbac\Abac;

class AbacTest extends \PHPUnit_Framework_TestCase
{
    /** @var Abac **/
    protected $abac;

    public function setUp()
    {
        $this->abac = new Abac([__DIR__ . '/fixtures/policy_rules.yml']);
    }

    public function testEnforce()
    {
        $visas = include('tests/fixtures/visas.php');
        $users = include('tests/fixtures/users.php');
        $vehicles = include('tests/fixtures/vehicles.php');
        $this->assertTrue($this->abac->enforce('nationality-access', $users[3]));
        $this->assertEquals([
            'japd',
        ], $this->abac->enforce('nationality-access', $users[1]));

        // getenv() don't work in CLI scripts without putenv()
        putenv('SERVICE_STATE=OPEN');
        
        $this->assertTrue($this->abac->enforce('vehicle-homologation', $users[0], $vehicles[0], [
            'dynamic_attributes' => ['proprietaire' => 1]
        ]));
        $this->assertEquals([
            'derniere-revision-technique'
        ],$this->abac->enforce('vehicle-homologation', $users[2], $vehicles[1], [
            'dynamic_attributes' => ['proprietaire' => 3]
        ]));
        $this->assertEquals([
            'permis-de-conduire'
        ], $this->abac->enforce('vehicle-homologation', $users[3], $vehicles[3], [
            'dynamic_attributes' => ['proprietaire' => 4]
        ]));
    }
}<commit_msg>Add tests of the enforce method with extra data<commit_after><?php

namespace PhpAbac\Test;

use PhpAbac\Abac;

class AbacTest extends \PHPUnit_Framework_TestCase
{
    /** @var Abac **/
    protected $abac;

    public function setUp()
    {
        $this->abac = new Abac([__DIR__ . '/fixtures/policy_rules.yml']);
    }

    public function testEnforce()
    {
        $visas = include('tests/fixtures/visas.php');
        $users = include('tests/fixtures/users.php');
        $vehicles = include('tests/fixtures/vehicles.php');
        $this->assertTrue($this->abac->enforce('nationality-access', $users[3]));
        $this->assertEquals([
            'japd',
        ], $this->abac->enforce('nationality-access', $users[1]));

        // getenv() don't work in CLI scripts without putenv()
        putenv('SERVICE_STATE=OPEN');
        
        $this->assertTrue($this->abac->enforce('vehicle-homologation', $users[0], $vehicles[0], [
            'dynamic_attributes' => ['proprietaire' => 1]
        ]));
        $this->assertEquals([
            'derniere-revision-technique'
        ],$this->abac->enforce('vehicle-homologation', $users[2], $vehicles[1], [
            'dynamic_attributes' => ['proprietaire' => 3]
        ]));
        $this->assertEquals([
            'permis-de-conduire'
        ], $this->abac->enforce('vehicle-homologation', $users[3], $vehicles[3], [
            'dynamic_attributes' => ['proprietaire' => 4]
        ]));
        $this->assertEquals([
            'visas'
        ], $this->abac->enforce('travel-to-usa', $users[0]));
        $this->assertTrue($this->abac->enforce('travel-to-usa', $users[1]));
    }
}
{'fraction_non_alphanumeric': 0.18308943089430893, 'fraction_numerical': 0.007804878048780488, 'mean_word_length': 2.6273584905660377, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 53, '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': '1413026', 'n_tokens_mistral': 1003, 'n_tokens_neox': 978, 'n_words': 146}