<commit_before><?php

/**
 * @dataProvider ../../../databases.ini
 */

namespace Nextras\Orm\Tests\Integrations;

use Mockery;
use Nextras\Orm\Tests\Author;
use Nextras\Orm\Tests\DatabaseTestCase;
use Nextras\Orm\Tests\Book;
use Tester\Assert;

$dic = require_once __DIR__ . '/../../../bootstrap.php';


/**
 * @testCase
 */
class NewHasOneAddTest extends DatabaseTestCase
{

	public function testAutoConnection()
	{
		$author1 = $this->orm->authors->getById(1);

		$book = new Book();
		$book->title = 'A new book';
		$author1->books->add($book);
		Assert::true($author1->books->has($book));
		Assert::same($book->author, $author1);


		$book = new Book();
		$book->title = 'The second new book';
		$book->author = $author1;
		Assert::true($author1->books->has($book));
		Assert::same($book->author, $author1);


		$author2 = $this->orm->authors->getById(2);
		$author2->books->add($book);
		Assert::false($author1->books->has($book));
		Assert::true($author2->books->has($book));
		Assert::same($book->author, $author2);


		$book->author = $author1;
		Assert::false($author2->books->has($book));
		Assert::true($author1->books->has($book));
		Assert::same($book->author, $author1);
	}


	public function testPersistanceHasOne()
	{
		$author = new Author();
		$author->name = '<NAME>';

		$book = new Book();
		$this->orm->books->attach($book);
		$book->title = 'A new book';
		$book->author = $author;

		$this->orm->books->persistAndFlush($book);

		Assert::true($author->isPersisted());
		Assert::false($author->isModified());
		Assert::same(3, $author->id);
	}

}


$test = new NewHasOneAddTest($dic);
$test->run();<commit_msg>[tests] fixed weird nette/tester method run order<commit_after><?php

/**
 * @dataProvider ../../../databases.ini
 */

namespace Nextras\Orm\Tests\Integrations;

use Mockery;
use Nextras\Orm\Tests\Author;
use Nextras\Orm\Tests\DatabaseTestCase;
use Nextras\Orm\Tests\Book;
use Tester\Assert;

$dic = require_once __DIR__ . '/../../../bootstrap.php';


/**
 * @testCase
 */
class NewHasOneAddTest extends DatabaseTestCase
{

	public function testAutoConnection()
	{
		$author1 = $this->orm->authors->getById(1);

		$book = new Book();
		$book->title = 'A new book';
		$author1->books->add($book);
		Assert::true($author1->books->has($book));
		Assert::same($book->author, $author1);


		$book = new Book();
		$book->title = 'The second new book';
		$book->author = $author1;
		Assert::true($author1->books->has($book));
		Assert::same($book->author, $author1);


		$author2 = $this->orm->authors->getById(2);
		$author2->books->add($book);
		Assert::false($author1->books->has($book));
		Assert::true($author2->books->has($book));
		Assert::same($book->author, $author2);


		$book->author = $author1;
		Assert::false($author2->books->has($book));
		Assert::true($author1->books->has($book));
		Assert::same($book->author, $author1);
	}


	public function testPersistanceHasOne()
	{
		$author = new Author();
		$author->name = '<NAME>';

		$book = new Book();
		$this->orm->books->attach($book);
		$book->title = 'A new book';
		$book->author = $author;

		$this->orm->books->persistAndFlush($book);

		Assert::true($author->isPersisted());
		Assert::false($author->isModified());
	}

}


$test = new NewHasOneAddTest($dic);
$test->run();
{'fraction_non_alphanumeric': 0.22201834862385322, 'fraction_numerical': 0.011314984709480122, 'mean_word_length': 4.534686971235194, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 90, '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': '2493484', 'n_tokens_mistral': 1239, 'n_tokens_neox': 1142, 'n_words': 189}