<commit_before><?php

namespace WFV;

use WFV\Factory\ValidationFactory;

class ValidatorTest extends \PHPUnit_Framework_TestCase {

  const FORM = array(
    'action'  => 'phpunit', // unique identifier
    'rules'   => array(
      'name'      => ['required']
    )
  );

  const HTTP_POST = array(
    'action' => 'phpunit',
    'name' => 'Foo Bar'
  );

  protected static $form_no_post;

  protected static $form_has_post;

  // there are a lot of possible cases
  // planning the automation...

  public static function setUpBeforeClass() {
    $form_no_post = self::FORM;
    ValidationFactory::create( $form_no_post );
    self::$form_no_post = $form_no_post;

    $_POST = self::HTTP_POST;
    ValidationFactory::create( $form_has_post );
    self::$form_has_post = $form_has_post;
  }

  /**
   * is the factory building all instances and assigning
   *  them as properties to WFV\Validator when there is no $_POST?
   *
   */
  public function test_validator_factory_create_with_no_post() {
    $this->assertInstanceOf( 'WFV\Validator', self::$form_no_post );
    $this->assertInstanceOf( 'WFV\Errors', self::$form_no_post->errors );
    $this->assertInstanceOf( 'WFV\Input', self::$form_no_post->input );
    $this->assertInstanceOf( 'WFV\Messages', self::$form_no_post->messages );
    $this->assertInstanceOf( 'WFV\Rules', self::$form_no_post->rules );
  }

  /**
   * $_POST exists - is the factory building all instances and assigning
   *  them as properties to WFV\Validator?
   *
   */
  public function test_validator_factory_create_with_post() {
    $this->assertInstanceOf( 'WFV\Validator', self::$form_has_post );
    $this->assertInstanceOf( 'WFV\Errors', self::$form_has_post->errors );
    $this->assertInstanceOf( 'WFV\Input', self::$form_has_post->input );
    $this->assertInstanceOf( 'WFV\Messages', self::$form_has_post->messages );
    $this->assertInstanceOf( 'WFV\Rules', self::$form_has_post->rules );
  }
}
<commit_msg>phpunit - ValidatorTest - reword to eliminate redundant code<commit_after><?php

namespace WFV;

use WFV\Factory\ValidationFactory;

class ValidatorTest extends \PHPUnit_Framework_TestCase {

  const FORM = array(
    'action'  => 'phpunit', // unique identifier
    'rules'   => array(
      'name'      => ['required']
    )
  );

  const HTTP_POST = array(
    'action' => 'phpunit',
    'name' => 'Foo Bar'
  );

  protected static $form_no_post;

  protected static $form_has_post;

  // there are a lot of possible cases
  // planning the automation...

  public static function setUpBeforeClass() {
    $form_no_post = self::FORM;
    ValidationFactory::create( $form_no_post );
    self::$form_no_post = $form_no_post;

    // needs to happen after no POST instance setup
    // otherwise first instance will also grab $_POST...
    $_POST = self::HTTP_POST;
    ValidationFactory::create( $form_has_post );
    self::$form_has_post = $form_has_post;
  }

  /**
   * is the factory building all instances and assigning
   *  them as properties
   *
   */
  public function test_validator_factory_create_instances() {

    $forms = array(
      'has_post' => self::$form_has_post,
      'no_post'  => self::$form_no_post
    );

    // assert with and without $_POST
    foreach( $forms as $type => $form ) {
      $this->assertInstanceOf( 'WFV\Validator', $form );
      $this->assertInstanceOf( 'WFV\Errors', $form->errors );
      $this->assertInstanceOf( 'WFV\Input', $form->input );
      $this->assertInstanceOf( 'WFV\Messages', $form->messages );
      $this->assertInstanceOf( 'WFV\Rules', $form->rules );
    }
  }
}

{'fraction_non_alphanumeric': 0.14046822742474915, 'fraction_numerical': 0.0, 'mean_word_length': 3.5603557814485387, 'pattern_counts': {'":': 0, '<': 5, '<?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': '3065689', 'n_tokens_mistral': 1175, 'n_tokens_neox': 1156, 'n_words': 255}