<commit_before><?php

/*
 * This file is part of the RollerworksSearch package.
 *
 * (c) <NAME> <<EMAIL>>
 *
 * This source file is subject to the MIT license that is bundled
 * with this source code in the file LICENSE.
 */

namespace Rollerworks\Component\Search\Tests\Doctrine\Orm;

use Rollerworks\Component\Search\Doctrine\Orm\AbstractWhereBuilder;
use Rollerworks\Component\Search\Exception\InvalidSearchConditionException;
use Rollerworks\Component\Search\FieldAliasResolver\NoopAliasResolver;
use Rollerworks\Component\Search\Input\FilterQueryInput;
use Rollerworks\Component\Search\Input\ProcessorConfig;
use Rollerworks\Component\Search\Tests\Doctrine\Dbal\SchemaRecord;
use Rollerworks\Component\Search\ValuesGroup;

/**
 * Ensures the expected results are actually found.
 *
 * Uses the FilterQuery input-processor for a readable condition
 * and ensures the input values are properly formatted.
 *
 * This example uses a 'classic' invoice system
 * with three tables:
 *
 * * invoices
 * * invoice_rows
 * * customers
 *
 * For simplicity this example doesn't do tax calculation.
 *
 * Complex structure tests are not done here as these tests are more about
 * "doesn't error".
 */
class WhereBuilderResultsTestCase extends OrmTestCase
{
    /**
     * @var FilterQueryInput
     */
    private $inputProcessor;

    protected function setUp()
    {
        parent::setUp();

        $this->inputProcessor = new FilterQueryInput(new NoopAliasResolver());
    }

    /**
     * @return SchemaRecord[]
     */
    protected function getDbRecords()
    {
        $date = function ($input) {
            return new \DateTime($input, new \DateTimeZone('UTC'));
        };

        return [
            SchemaRecord::create(
                'customers',
                [
                    'id' => 'integer',
                    'first_name' => 'string',
                    'last_name' => 'string',
                    'birthday' => 'date',
                ]
            )
            ->records()
                ->add([1, 'Peter', 'Pang', $date('1980-11-20')])
                ->add([2, 'Leroy', 'Jenkins', $date('2000-05-15')])
                ->add([3, 'Doctor', 'Who', $date('2005-12-10')])
                ->add([4, 'Spider', 'Pig', $date('2012-06-10')])
            ->end(),

            // Two invoices are paid, one is a concept and three are unpaid
            SchemaRecord::create(
                'invoices',
                [
                    'invoice_id' => 'integer',
                    'customer' => 'integer',
                    'label' => 'string',
                    'pubdate' => 'date',
                    'status' => 'integer',
                ]
            )
            ->records()
                ->add([1, 1, '2010-001', $date('2010-05-10'), 2]) // 'Peter', 'Pang'
                ->add([2, 2, '2010-002', $date('2010-05-10'), 2]) // 'Leroy', 'Jenkins'
                ->add([3, 2, null, null, '10.00']) // concept - 'Leroy', 'Jenkins'
                // unpaid //
                ->add([4, 2, '2015-001', $date('2015-05-10'), 1]) // 'Leroy', 'Jenkins'<commit_msg>Fix broken tests<commit_after><?php

/*
 * This file is part of the RollerworksSearch package.
 *
 * (c) <NAME> <<EMAIL>>
 *
 * This source file is subject to the MIT license that is bundled
 * with this source code in the file LICENSE.
 */

namespace Rollerworks\Component\Search\Tests\Doctrine\Orm;

use Rollerworks\Component\Search\Doctrine\Orm\AbstractWhereBuilder;
use Rollerworks\Component\Search\Exception\InvalidSearchConditionException;
use Rollerworks\Component\Search\FieldAliasResolver\NoopAliasResolver;
use Rollerworks\Component\Search\Input\FilterQueryInput;
use Rollerworks\Component\Search\Input\ProcessorConfig;
use Rollerworks\Component\Search\Tests\Doctrine\Dbal\SchemaRecord;
use Rollerworks\Component\Search\ValuesGroup;

/**
 * Ensures the expected results are actually found.
 *
 * Uses the FilterQuery input-processor for a readable condition
 * and ensures the input values are properly formatted.
 *
 * This example uses a 'classic' invoice system
 * with three tables:
 *
 * * invoices
 * * invoice_rows
 * * customers
 *
 * For simplicity this example doesn't do tax calculation.
 *
 * Complex structure tests are not done here as these tests are more about
 * "doesn't error".
 */
class WhereBuilderResultsTestCase extends OrmTestCase
{
    /**
     * @var FilterQueryInput
     */
    private $inputProcessor;

    protected function setUp()
    {
        parent::setUp();

        $this->inputProcessor = new FilterQueryInput(new NoopAliasResolver());
    }

    /**
     * @return SchemaRecord[]
     */
    protected function getDbRecords()
    {
        $date = function ($input) {
            return new \DateTime($input, new \DateTimeZone('UTC'));
        };

        return [
            SchemaRecord::create(
                'customers',
                [
                    'id' => 'integer',
                    'first_name' => 'string',
                    'last_name' => 'string',
                    'birthday' => 'date',
                ]
            )
            ->records()
                ->add([1, 'Peter', 'Pang', $date('1980-11-20')])
                ->add([2, 'Leroy', 'Jenkins', $date('2000-05-15')])
                ->add([3, 'Doctor', 'Who', $date('2005-12-10')])
                ->add([4, 'Spider', 'Pig', $date('2012-06-10')])
            ->end(),

            // Two invoices are paid, one is a concept and three are unpaid
            SchemaRecord::create(
                'invoices',
                [
                    'invoice_id' => 'integer',
                    'customer' => 'integer',
                    'label' => 'string',
                    'pubdate' => 'date',
                    'status' => 'integer',
                ]
            )
            ->records()
                ->add([1, 1, '2010-001', $date('2010-05-10'), 2]) // 'Peter', 'Pang'
                ->add([2, 2, '2010-002', $date('2010-05-10'), 2]) // 'Leroy', 'Jenkins'
                ->add([3, 2, null, null, 0]) // concept - 'Leroy', 'Jenkins'
                // unpaid //
                ->add([4, 2, '2015-001', $date('2015-05-10'), 1]) // 'Leroy', 'Jenkins'
{'fraction_non_alphanumeric': 0.14350136898051216, 'fraction_numerical': 0.030439684329199548, 'mean_word_length': 1.9942140790742526, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 51, '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': '7134561', 'n_tokens_mistral': 1939, 'n_tokens_neox': 1725, 'n_words': 441}