<commit_before><?php

namespace WFV;

use WFV\Rules;

class RulesTest extends \PHPUnit_Framework_TestCase {

  const RULES = array(
    'first_name' => ['required', 'alpha'],
    'last_name' => ['required', 'alpha'],
    'phone'      => ['required', 'custom:phone'],
    'username'   => ['required'],
    'password'   => ['<PASSWORD>'],
    'email'      => ['email','required'],
    'website'    => ['required', 'url'],
    'postal'     => ['custom:postal_code'],
  );

  /**
   * Are the rules array keys set as property names?
   *
   */
  public function test_rules_get_set_as_properties() {
    $rules = new Rules();
    $rules->set( self::RULES );

    foreach( $rules as $field => $ruleset ) {
      $this->assertTrue( property_exists( $rules, $field ) );
    }
  }

  /**
   * Is the ruleset for each field assigned from the rules array
   *  to the field property?
   *
   */
  public function test_rules_if_field_has_rules() {
    $rules = new Rules();
    $rules->set( self::RULES );

    foreach( $rules as $field => $ruleset ) {
      foreach( $ruleset as $index => $rule ) {
        $has_rule = ( $rule === self::RULES[$field][$index] ) ? true : false;
        $this->assertTrue( $has_rule );
      }
    }
  }

  /**
   * Does is_custom return true if rule is custom?
   *
   */
  public function test_rule_is_custom_returns_true() {
    $rules = new Rules();
    $this->assertTrue( $rules->is_custom('custom:phone') );
  }

  /**
   * Does is_custom return false if rule is NOT custom?
   *
   */
  public function test_rule_is_custom_returns_false() {
    $rules = new Rules();
    $this->assertFalse( $rules->is_custom('required') );
  }
}
<commit_msg>RulesTest - class constant now static property - for php5.4 compatibility<commit_after><?php

namespace WFV;

use WFV\Rules;

class RulesTest extends \PHPUnit_Framework_TestCase {

  /**
   *
   *
   * @access protected
   * @var
   */
  protected static $rules;

  /**
   *
   *
   */
  public static function setUpBeforeClass() {
    self::$rules = array(
      'first_name' => ['required', 'alpha'],
      'last_name' => ['required', 'alpha'],
      'phone'      => ['required', 'custom:phone'],
      'username'   => ['required'],
      'password'   => ['<PASSWORD>'],
      'email'      => ['email','required'],
      'website'    => ['required', 'url'],
      'postal'     => ['custom:postal_code'],
    );
  }

  /**
   *
   *
   */
  public static function tearDownAfterClass() {

  }

  /**
   * Are the rules array keys set as property names?
   *
   */
  public function test_rules_get_set_as_properties() {
    $rules = new Rules();
    $rules->set( self::$rules );

    foreach( $rules as $field => $ruleset ) {
      $this->assertTrue( property_exists( $rules, $field ) );
    }
  }

  /**
   * Is the ruleset for each field assigned from the rules array
   *  to the field property?
   *
   */
  public function test_rules_if_field_has_rules() {
    $rules = new Rules();
    $rules->set( self::$rules );

    foreach( $rules as $field => $ruleset ) {
      foreach( $ruleset as $index => $rule ) {
        $has_rule = ( $rule === self::$rules[$field][$index] ) ? true : false;
        $this->assertTrue( $has_rule );
      }
    }
  }

  /**
   * Does is_custom return true if rule is custom?
   *
   */
  public function test_rule_is_custom_returns_true() {
    $rules = new Rules();
    $this->assertTrue( $rules->is_custom('custom:phone') );
  }

  /**
   * Does is_custom return false if rule is NOT custom?
   *
   */
  public function test_rule_is_custom_returns_false() {
    $rules = new Rules();
    $this->assertFalse( $rules->is_custom('required') );
  }
}

{'fraction_non_alphanumeric': 0.16643854366274294, 'fraction_numerical': 0.0005474952094169176, 'mean_word_length': 2.732379979570991, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 43, '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': '3785008', 'n_tokens_mistral': 1210, 'n_tokens_neox': 1197, 'n_words': 283}