<commit_before><?php

declare(strict_types=1);

/*
 * Jasper report integration for PHP
 *
 * @link      https://github.com/belgattitude/soluble-jasper
 * @author    <NAME>
 * @copyright Copyright (c) 2017 <NAME>
 * @license   MIT
 */

namespace JasperTest\Proxy\Data;

use PHPUnit\Framework\TestCase;
use Soluble\Japha\Bridge\Adapter as BridgeAdapter;
use Soluble\Jasper\Exception\FileNotFoundException;
use Soluble\Jasper\Exception\InvalidArgumentException;
use Soluble\Jasper\Proxy\Data\JsonDataAdapterImpl;

class JsonDataAdapterImplTest extends TestCase
{
    /**
     * @var BridgeAdapter
     */
    protected $ba;

    public function setUp(): void
    {
        $this->ba = \JasperTestsFactories::getJavaBridgeAdapter();
    }

    public function testProperties(): void
    {
        $jsonAdapter = new JsonDataAdapterImpl($this->ba);
        $jsonAdapter->setLocale('en_GB');
        $jsonAdapter->setNumberPattern('#,##0.##');
        $jsonAdapter->setLanguage(JsonDataAdapterImpl::LANGUAGE_JSONQL);
        $jsonAdapter->setDatePattern('yyyy-MM-dd');
        $jsonAdapter->setUseConnection(false);

        $javaObject = $jsonAdapter->getJavaProxiedObject();

        self::assertEquals('#,##0.##', (string) $javaObject->getNumberPattern());
        self::assertEquals('yyyy-MM-dd', (string) $javaObject->getDatePattern());
        self::assertEquals('en_gb', mb_strtolower((string) $javaObject->getLocale()));
        self::assertEquals(JsonDataAdapterImpl::LANGUAGE_JSONQL, (string) $javaObject->getLanguage());
        self::assertEquals(false, $javaObject->isUseConnection());

        $jsonAdapter->setLanguage(JsonDataAdapterImpl::LANGUAGE_JSON);
        self::assertEquals(JsonDataAdapterImpl::LANGUAGE_JSON, (string) $javaObject->getLanguage());
    }

    public function testSetFileName(): void
    {
        $jsonFile    = \JasperTestsFactories::getDataBaseDir() . '/northwind.json';
        $jsonAdapter = new JsonDataAdapterImpl($this->ba);
        $jsonAdapter->setFileName($jsonFile);
        $javaObject = $jsonAdapter->getJavaProxiedObject();
        self::assertEquals($jsonFile, (string) $javaObject->getFileName());
    }

    public function testSetFileNameThrowsException(): void
    {
        $this->expectException(FileNotFoundException::class);
        $jsonFile    = \JasperTestsFactories::getDataBaseDir() . '/filenotexist.json';
        $jsonAdapter = new JsonDataAdapterImpl($this->ba);
        $jsonAdapter->setFileName($jsonFile);
    }

    public function testSetLanguageThrowsException(): void
    {
        $this->expectException(InvalidArgumentException::class);<commit_msg>small fix detected by phpcs<commit_after><?php

declare(strict_types=1);

/*
 * Jasper report integration for PHP
 *
 * @link      https://github.com/belgattitude/soluble-jasper
 * @author    <NAME>
 * @copyright Copyright (c) 2017 <NAME>
 * @license   MIT
 */

namespace JasperTest\Proxy\Data;

use PHPUnit\Framework\TestCase;
use Soluble\Japha\Bridge\Adapter as BridgeAdapter;
use Soluble\Jasper\Exception\FileNotFoundException;
use Soluble\Jasper\Exception\InvalidArgumentException;
use Soluble\Jasper\Proxy\Data\JsonDataAdapterImpl;

class JsonDataAdapterImplTest extends TestCase
{
    /**
     * @var BridgeAdapter
     */
    protected $ba;

    public function setUp(): void
    {
        $this->ba = \JasperTestsFactories::getJavaBridgeAdapter();
    }

    public function testProperties(): void
    {
        $jsonAdapter = new JsonDataAdapterImpl($this->ba);
        $jsonAdapter->setLocale('en_GB');
        $jsonAdapter->setNumberPattern('#,##0.##');
        $jsonAdapter->setLanguage(JsonDataAdapterImpl::LANGUAGE_JSONQL);
        $jsonAdapter->setDatePattern('yyyy-MM-dd');
        $jsonAdapter->setUseConnection(false);

        $javaObject = $jsonAdapter->getJavaProxiedObject();

        self::assertEquals('#,##0.##', (string) $javaObject->getNumberPattern());
        self::assertEquals('yyyy-MM-dd', (string) $javaObject->getDatePattern());
        self::assertEquals('en_gb', mb_strtolower((string) $javaObject->getLocale()));
        self::assertEquals(JsonDataAdapterImpl::LANGUAGE_JSONQL, (string) $javaObject->getLanguage());
        self::assertFalse($javaObject->isUseConnection());

        $jsonAdapter->setLanguage(JsonDataAdapterImpl::LANGUAGE_JSON);
        self::assertEquals(JsonDataAdapterImpl::LANGUAGE_JSON, (string) $javaObject->getLanguage());
    }

    public function testSetFileName(): void
    {
        $jsonFile    = \JasperTestsFactories::getDataBaseDir() . '/northwind.json';
        $jsonAdapter = new JsonDataAdapterImpl($this->ba);
        $jsonAdapter->setFileName($jsonFile);
        $javaObject = $jsonAdapter->getJavaProxiedObject();
        self::assertEquals($jsonFile, (string) $javaObject->getFileName());
    }

    public function testSetFileNameThrowsException(): void
    {
        $this->expectException(FileNotFoundException::class);
        $jsonFile    = \JasperTestsFactories::getDataBaseDir() . '/filenotexist.json';
        $jsonAdapter = new JsonDataAdapterImpl($this->ba);
        $jsonAdapter->setFileName($jsonFile);
    }

    public function testSetLanguageThrowsException(): void
    {
        $this->expectException(InvalidArgumentException::class);
{'fraction_non_alphanumeric': 0.1388042650418888, 'fraction_numerical': 0.0026656511805026656, 'mean_word_length': 4.07046332046332, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 53, 'https://': 2, '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': '3948528', 'n_tokens_mistral': 1521, 'n_tokens_neox': 1474, 'n_words': 224}