<commit_before><?php

declare(strict_types=1);

/*
 * This file is part of the BazingaGeocoderBundle package.
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 *
 * @license    MIT License
 */

namespace Bazinga\GeocoderBundle\Tests\Doctrine\ORM;

use Bazinga\GeocoderBundle\Doctrine\ORM\GeocoderListener;
use Bazinga\GeocoderBundle\Mapping\Driver\AnnotationDriver;
use Doctrine\Common\Annotations\AnnotationRegistry;
use Doctrine\Common\Annotations\SimpleAnnotationReader;
use Doctrine\DBAL\DriverManager;
use Doctrine\ORM\EntityManager;
use Doctrine\ORM\Tools\SchemaTool;
use Doctrine\Tests\DoctrineTestCase;
use Doctrine\Tests\OrmTestCase;
use Geocoder\Provider\GoogleMaps\GoogleMaps;
use Http\Client\Curl\Client;

/**
 * @author <NAME> <<EMAIL>>
 */
class GeocoderListenerTest extends OrmTestCase
{
    /**
     * @var EntityManager
     */
    private $em;

    /**
     * @var GeocoderListener
     */
    private $listener;

    public static function setUpBeforeClass()
    {
        if (!class_exists(DoctrineTestCase::class)) {
            /*
             * We check for DoctrineTestCase because it is in the same package as OrmTestCase and we want to be able to
             * fake OrmTestCase
             */
            static::fail('Doctrine\Tests\OrmTestCase was not found.');
        }
        parent::setUpBeforeClass();
    }

    protected function setUp()
    {
        AnnotationRegistry::registerLoader('class_exists');

        $conn = DriverManager::getConnection([
            'driver' => 'pdo_sqlite',
            'memory' => true,
        ]);

        $this->em = $this->_getTestEntityManager($conn);

        $reader = new SimpleAnnotationReader();
        $reader->addNamespace('Bazinga\GeocoderBundle\Mapping\Annotations');
        $reader->addNamespace('Doctrine\ORM\Mapping');

        $driver = new AnnotationDriver($reader);

        $geocoder = new GoogleMaps(new Client());

        $this->listener = new GeocoderListener($geocoder, $driver);

        $this->em->getEventManager()->addEventSubscriber($this->listener);

        $sm = new SchemaTool($this->em);
        $sm->createSchema([
            $this->em->getClassMetadata('Bazinga\GeocoderBundle\Tests\Doctrine\ORM\Dummy'),
        ]);
    }

    public function testPersist()
    {
        $dummy = new Dummy();
        $dummy->address = 'Berlin, Germany';

        $this->em->persist($dummy);
        $this->em->flush();

        $this->assertNotNull($dummy->latitude);
        $this->assertNotNull($dummy->longitude);
<commit_msg>Use Nominatim instad of google (#201)<commit_after><?php

declare(strict_types=1);

/*
 * This file is part of the BazingaGeocoderBundle package.
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 *
 * @license    MIT License
 */

namespace Bazinga\GeocoderBundle\Tests\Doctrine\ORM;

use Bazinga\GeocoderBundle\Doctrine\ORM\GeocoderListener;
use Bazinga\GeocoderBundle\Mapping\Driver\AnnotationDriver;
use Doctrine\Common\Annotations\AnnotationRegistry;
use Doctrine\Common\Annotations\SimpleAnnotationReader;
use Doctrine\DBAL\DriverManager;
use Doctrine\ORM\EntityManager;
use Doctrine\ORM\Tools\SchemaTool;
use Doctrine\Tests\DoctrineTestCase;
use Doctrine\Tests\OrmTestCase;
use Geocoder\Provider\Nominatim\Nominatim;
use Http\Client\Curl\Client;

/**
 * @author <NAME> <<EMAIL>>
 */
class GeocoderListenerTest extends OrmTestCase
{
    /**
     * @var EntityManager
     */
    private $em;

    /**
     * @var GeocoderListener
     */
    private $listener;

    public static function setUpBeforeClass()
    {
        if (!class_exists(DoctrineTestCase::class)) {
            /*
             * We check for DoctrineTestCase because it is in the same package as OrmTestCase and we want to be able to
             * fake OrmTestCase
             */
            static::fail('Doctrine\Tests\OrmTestCase was not found.');
        }
        parent::setUpBeforeClass();
    }

    protected function setUp()
    {
        AnnotationRegistry::registerLoader('class_exists');

        $conn = DriverManager::getConnection([
            'driver' => 'pdo_sqlite',
            'memory' => true,
        ]);

        $this->em = $this->_getTestEntityManager($conn);

        $reader = new SimpleAnnotationReader();
        $reader->addNamespace('Bazinga\GeocoderBundle\Mapping\Annotations');
        $reader->addNamespace('Doctrine\ORM\Mapping');

        $driver = new AnnotationDriver($reader);
        $geocoder = Nominatim::withOpenStreetMapServer(new Client(), 'BazingaGeocoderBundle/Test');
        $this->listener = new GeocoderListener($geocoder, $driver);

        $this->em->getEventManager()->addEventSubscriber($this->listener);

        $sm = new SchemaTool($this->em);
        $sm->createSchema([
            $this->em->getClassMetadata('Bazinga\GeocoderBundle\Tests\Doctrine\ORM\Dummy'),
        ]);
    }

    public function testPersist()
    {
        $dummy = new Dummy();
        $dummy->address = 'Berlin, Germany';

        $this->em->persist($dummy);
        $this->em->flush();

        $this->assertNotNull($dummy->latitude);
        $this->assertNotNull($dummy->longitude);

{'fraction_non_alphanumeric': 0.12447896930655551, 'fraction_numerical': 0.0009473285335354301, 'mean_word_length': 3.014448669201521, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 57, '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': '1876057', 'n_tokens_mistral': 1555, 'n_tokens_neox': 1513, 'n_words': 307}