<commit_before><?php

namespace Neducatio\TestBundle\Tests\Utility;

use Neducatio\TestBundle\Utility\WebClientRetriever;
use Mockery as m;

/**
 * TestClientRetriever
 *
 * @covers Neducatio\TestBundle\Utility\WebClientRetriever
 */
class WebClientRetrieverTest extends \PHPUnit_Framework_TestCase
{
  private $client;
  private $container;
  private $userReference;
  private $clientRetriever;
  private $form;
  private static $validServiceParams = array(
      'form_url' => '/login',
      'username_field_name' => '_username',
      'password_field_name' => <PASSWORD>',
      'submit_button_name' => '_submit'
  );
  private static $invalidServiceParams = array(
      'form_url' => '/login',
      'username_field_name' => '_username',
      'submit_button_name' => '_submit'
  );

  const USER_NAME = '<EMAIL>';

  /**
   * Test for constructor
   *
   * @test
   */
  public function assertInstanceOfWebClientRetriever()
  {
    $this->assertInstanceOf('Neducatio\TestBundle\Utility\WebClientRetriever', $this->clientRetriever);
  }

  /**
   * Test for setClient
   *
   * @test
   */
  public function shouldSetClientWhenValidServiceParamsGiven()
  {
    $this->container->shouldReceive('hasParameter')->with('neducatio_test.web_client_login_form_params')->andReturn(true);
    $this->container->shouldReceive('getParameter')->with('neducatio_test.web_client_login_form_params')->andReturn(self::$validServiceParams);
    $result = $this->clientRetriever->setClient($this->userReference);

    $this->assertEquals($this->client, $result);
  }

  /**
   * Test for setClient
   *
   * @test
   */
  public function setClient_shouldThrowExceptionWhenInvalidServiceParamsGiven()
  {
    $this->container->shouldReceive('hasParameter')->with('neducatio_test.web_client_login_form_params')->andReturn(true);
    $this->container->shouldReceive('getParameter')->with('neducatio_test.web_client_login_form_params')->andReturn(self::$invalidServiceParams);
    $this->setExpectedException('\Neducatio\TestBundle\Utility\LoginFormParameterNotFoundException');

    $this->clientRetriever->setClient($this->userReference);
  }

  /**
   * Test for setClient
   *
   * @test
   */
  public function setClient_shouldThrowExceptionWhenServiceNotConfigured()
  {
    $this->container->shouldReceive('hasParameter')->with('neducatio_test.web_client_login_form_params')->andReturn(false);
    $this->setExpectedException('\Neducatio\TestBundle\Utility\LoginFormParameterNotFoundException');

    $this->clientRetriever->setClient($this->userReference);
  }

  /**
   * Prepares mocks.
   */
  public function setUp()
  {
    $this->form = m::mock('Symfony\Component\DomCrawler\Form');
    $this->client = $this->getWebClientMock();
    $this->userReference = m::mock('FOS\UserBundle\Entity\User');
    $this->userReference->shouldReceive('getUsername')->andReturn(self::USER_NAME);
    $this->container = $this->getContainerMock();
    $this->clientRetriever = new WebClientRetriever($this->container);
  }

  /**
   * Tears down.
   */
  public function tearDown()
  {
    m::close();
  }

  private function getCrawlerMock()
  {
    $crawlerWithFilteredListOfNodes = m::mock('stdClass');
    $crawlerWithFilteredListOfNodes->shouldReceive('form')->andReturn($this->form);
<commit_msg>Naprawa 3 zepsutych testow - brakowalo parametru.<commit_after><?php

namespace Neducatio\TestBundle\Tests\Utility;

use Neducatio\TestBundle\Utility\WebClientRetriever;
use Mockery as m;

/**
 * TestClientRetriever
 *
 * @covers Neducatio\TestBundle\Utility\WebClientRetriever
 */
class WebClientRetrieverTest extends \PHPUnit_Framework_TestCase
{
  private $client;
  private $container;
  private $userReference;
  private $clientRetriever;
  private $form;
  private static $validServiceParams = array(
      'form_url' => '/login',
      'username_field_name' => '_username',
      'password_field_name' => <PASSWORD>',
      'submit_button_name' => '_submit'
  );
  private static $invalidServiceParams = array(
      'form_url' => '/login',
      'username_field_name' => '_username',
      'submit_button_name' => '_submit'
  );

  const USER_NAME = '<EMAIL>';

  /**
   * Test for constructor
   *
   * @test
   */
  public function assertInstanceOfWebClientRetriever()
  {
    $this->assertInstanceOf('Neducatio\TestBundle\Utility\WebClientRetriever', $this->clientRetriever);
  }

  /**
   * Test for setClient
   *
   * @test
   */
  public function shouldSetClientWhenValidServiceParamsGiven()
  {
    $this->container->shouldReceive('hasParameter')->with('neducatio_test.web_client_login_form_params')->andReturn(true);
    $this->container->shouldReceive('getParameter')->with('neducatio_test.web_client_login_form_params')->andReturn(self::$validServiceParams);
    $result = $this->clientRetriever->setClient($this->userReference, false);

    $this->assertEquals($this->client, $result);
  }

  /**
   * Test for setClient
   *
   * @test
   */
  public function setClient_shouldThrowExceptionWhenInvalidServiceParamsGiven()
  {
    $this->container->shouldReceive('hasParameter')->with('neducatio_test.web_client_login_form_params')->andReturn(true);
    $this->container->shouldReceive('getParameter')->with('neducatio_test.web_client_login_form_params')->andReturn(self::$invalidServiceParams);
    $this->setExpectedException('\Neducatio\TestBundle\Utility\LoginFormParameterNotFoundException');

    $this->clientRetriever->setClient($this->userReference, false);
  }

  /**
   * Test for setClient
   *
   * @test
   */
  public function setClient_shouldThrowExceptionWhenServiceNotConfigured()
  {
    $this->container->shouldReceive('hasParameter')->with('neducatio_test.web_client_login_form_params')->andReturn(false);
    $this->setExpectedException('\Neducatio\TestBundle\Utility\LoginFormParameterNotFoundException');

    $this->clientRetriever->setClient($this->userReference, false);
  }

  /**
   * Prepares mocks.
   */
  public function setUp()
  {
    $this->form = m::mock('Symfony\Component\DomCrawler\Form');
    $this->client = $this->getWebClientMock();
    $this->userReference = m::mock('FOS\UserBundle\Entity\User');
    $this->userReference->shouldReceive('getUsername')->andReturn(self::USER_NAME);
    $this->container = $this->getContainerMock();
    $this->clientRetriever = new WebClientRetriever($this->container);
  }

  /**
   * Tears down.
   */
  public function tearDown()
  {
    m::close();
  }

  private function getCrawlerMock()
  {
    $crawlerWithFilteredListOfNodes = m::mock('stdClass');
    $crawlerWithFilteredListOfNodes->shouldReceive('form')->andReturn($this->form);

{'fraction_non_alphanumeric': 0.1457483763781906, 'fraction_numerical': 0.00015103458692040478, 'mean_word_length': 4.829225352112676, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 119, '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': '4669858', 'n_tokens_mistral': 2070, 'n_tokens_neox': 2052, 'n_words': 254}