<commit_before><?php
/******************************************************************************
 * An implementation of dicto (scg.unibe.ch/dicto) in and for PHP.
 *
 * Copyright (c) 2016, 2015 <NAME> <<EMAIL>>
 *
 * This software is licensed under The MIT License. You should have received
 * a copy of the license along with the code.
 */

use Lechimp\Dicto\Rules as R;
use Lechimp\Dicto\Variables as V;
use Lechimp\Dicto\Analysis\Violation;

require_once(__DIR__."/RuleTest.php");

class DependOnTest extends RuleTest {
    /**
     * @return  R\Schema
     */
    public function schema() {
        return new R\DependOn();
    }

    protected function only_a_classes_can_depend_on_globals() {
        return new R\Rule
            ( R\Rule::MODE_ONLY_CAN
            , new V\WithProperty
                ( new V\Classes()
                , new V\Name()
                , array("A.*")
                )
            , new R\DependOn()
            , array(new V\Globals())
            );
    }

    public function test_rule1_no_violation_1() {
        $rule = $this->only_a_classes_can_depend_on_globals();
        $code = <<<CODE
<?php

class BClass {
}

CODE;

        $violations = $this->analyze($rule, $code);
        $this->assertCount(0, $violations);
    }

    public function test_rule1_no_violation_2() {
        $rule = $this->only_a_classes_can_depend_on_globals();
        $code = <<<CODE
<?php

class AClass {
    public function a_method() {
        global \$foo;
    }
}

CODE;<commit_msg>made depend-on tests with only can a little easier for the moment by explicitly taking methods into account.<commit_after><?php
/******************************************************************************
 * An implementation of dicto (scg.unibe.ch/dicto) in and for PHP.
 *
 * Copyright (c) 2016, 2015 <NAME> <<EMAIL>>
 *
 * This software is licensed under The MIT License. You should have received
 * a copy of the license along with the code.
 */

use Lechimp\Dicto\Rules as R;
use Lechimp\Dicto\Variables as V;
use Lechimp\Dicto\Analysis\Violation;

require_once(__DIR__."/RuleTest.php");

class DependOnTest extends RuleTest {
    /**
     * @return  R\Schema
     */
    public function schema() {
        return new R\DependOn();
    }

    protected function only_a_classes_can_depend_on_globals() {
        $a_classes = new V\WithProperty
                ( new V\Classes()
                , new V\Name()
                , array("A.*")
                );
        $methods_in_a_classes = new V\WithProperty
                ( new V\Methods()
                , new V\In()
                , array($a_classes)
                );
        return new R\Rule
            ( R\Rule::MODE_ONLY_CAN
            , new V\Any(array($a_classes, $methods_in_a_classes))
            , new R\DependOn()
            , array(new V\Globals())
            );
    }

    public function test_rule1_no_violation_1() {
        $rule = $this->only_a_classes_can_depend_on_globals();
        $code = <<<CODE
<?php

class BClass {
}

CODE;

        $violations = $this->analyze($rule, $code);
        $this->assertCount(0, $violations);
    }

    public function test_rule1_no_violation_2() {
        $rule = $this->only_a_classes_can_depend_on_globals();
        $code = <<<CODE
<?php

class AClass {
    public function a_method() {
        global \$foo;
    }
}

CODE;
{'fraction_non_alphanumeric': 0.15855106888361045, 'fraction_numerical': 0.007719714964370546, 'mean_word_length': 2.3094302554027504, 'pattern_counts': {'":': 0, '<': 27, '<?xml version=': 0, '>': 17, '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': '1966201', 'n_tokens_mistral': 1079, 'n_tokens_neox': 1023, 'n_words': 248}