/ / Test funkcjonalny wiadomości e-mail kończy się niepowodzeniem, jeśli testowana akcja przekierowuje - php, symfony, testy funkcjonalne, swiftmailer

Test funkcjonalny wiadomości e-mail nie powiedzie się, jeśli przetestowane działania przekierowują - php, symfony, testowanie funkcjonalne, swiftmailer

Akcja kontrolera powoduje wysłanie wiadomości e-maila następnie przekierowania. Test funkcjonalny tej akcji kończy się niepowodzeniem z powodu przekierowania. Jeśli kontroler zostanie przepisany w celu renderowania szablonu, test przechodzi. [To wydaje się być ogólnie prawdziwe; sytuację można powtórzyć za pomocą kodu w dokumentacji [Symfony ”] [1]].

Edytuj: błąd testu

„/ usr / bin / php” „/ usr / bin / phpunit” „--colors”„--log-junit” „/tmp/nb-phpunit-log.xml” „--bootstrap” „/home/george/volunteer/app/bootstrap.php.cache” „--configuration” „/home/george/volunteer/app/phpunit.xml.dist” „--filter” „% btestActivateOrganizationb%” „/home/george/netbeans-8.0.1/php/phpunit/NetBeansSuite.php” "--run = / home / george / volunteer / src / Truckee / MatchingBundle / Tests / Controller / AdminControllerTest.php" PHPUnit 3.7.28 autorstwa Sebastiana Bergmanna.

Konfiguracja odczytana z /home/george/volunteer/app/phpunit.xml.dist

fa

Czas: 1,36 sekundy, pamięć: 40,75 MB

Wystąpiła 1 awaria:

1) TruckeeMatchingBundleTestsControllerAdminControllerTest :: testActivateOrganization Nie udało się potwierdzić, że oczekuje się 0 meczów 1.

/home/george/volunteer/src/Truckee/MatchingBundle/Tests/Controller/AdminControllerTest.php:64

AWARIE! Testy: 1, twierdzenia: 1, awarie: 1.

Gotowe.

Kontroler

public function activateOrgAction($id)
{
$em = $this->getDoctrine()->getManager();
$organization = $em->getRepository("TruckeeMatchingBundle:Organization")->find($id);
$temp = $organization->getTemp();
if (true === $temp) {
$organization->setTemp(false);
$organization->setActive(true);
$orgName = $organization->getOrgName();
$em->persist($organization);
$em->flush();
$to = $em->getRepository("TruckeeMatchingBundle:Staff")->getActivePersons($id);
$mailer = $this->container->get("admin.mailer");
$mailer->activateOrgMail($organization, $to);
$flash = $this->get("braincrafted_bootstrap.flash");
$flash->success("$orgName has been activated");
}

return $this->redirect($this->generateUrl("admin_home"));
}

Edytuj 3: Bardziej kompletne urządzenie testowe

class AdminControllerTest extends WebTestCase
{

private $client;

public function setUp()
{
$classes = array(
"TruckeeMatchingBundleDataFixturesSampleDataLoadFocusSkillData",
"TruckeeMatchingBundleDataFixturesSampleDataLoadAdminUser",
"TruckeeMatchingBundleDataFixturesSampleDataLoadStaffUserGlenshire",
"TruckeeMatchingBundleDataFixturesSampleDataLoadStaffUserMelanzane",
"TruckeeMatchingBundleDataFixturesSampleDataLoadTemplateData",
"TruckeeMatchingBundleDataFixturesSampleDataLoadOpportunity",
"TruckeeMatchingBundleDataFixturesSampleDataLoadVolunteer",
);
$this->loadFixtures($classes);
$this->client = $this->createClient();
$this->client->followRedirects();
}

public function login($user)
{
$crawler = $this->client->request("GET", "/login");
$form = $crawler->selectButton("Login")->form();
$form["_username"] = $user;
$form["_password"] = "123Abcd";
$crawler = $this->client->submit($form);

return $crawler;
}
public function testActivateOrganization()
{
$crawler = $this->login("admin");
$link = $crawler->selectLink("Accept organization")->link();
$crawler = $this->client->click($link);

$mailCollector = $this->client->getProfile()->getCollector("swiftmailer");
$this->assertEquals(1, $mailCollector->getMessageCount());
}
...
}

Odpowiedzi:

1 dla odpowiedzi № 1

Dodaj to do swojego testu jednostkowego:

 $this->client->followRedirects(false);

Zobacz Symfony dokumentuje testowanie. Przekierowania nie są śledzone automatycznie, ale ustawiasz je do tego. Jeśli chcesz śledzić następne przekierowanie po przetestowaniu wiadomości e-mail, możesz zadzwonić

$crawler = $client->followRedirect();

Jeśli chcesz wrócić do śledzenia wszystkich przekierowań, zadzwoń:

$client->followRedirects();