-defmodule UsingAppsignalPhoenix do
-  def call(conn, _opts) do
-    conn |> Plug.Conn.assign(:called?, true)
+defmodule PhoenixWithAppSignal do
+  use Plug.Router
+  use Appsignal.Phoenix
+  use Plug.ErrorHandler
+
+  plug(:match)
+  plug(:dispatch)
+
+  get "/" do
+    send_resp(conn, 200, "Welcome")
   end
 
-  defoverridable call: 2
-
-  use Appsignal.Phoenix
-end
-
-defmodule UsingAppsignalPhoenixWithException do
-  def call(_conn, _opts) do
-    raise "exception!"
+  get "/exception" do
+    raise("Exception!")
+    send_resp(conn, 200, "Welcome")
   end
-
-  defoverridable call: 2
-
-  use Appsignal.Phoenix
-end
-
-defmodule UsingAppsignalPhoenixWithTimeout do
-  def call(_conn, _opts) do
-    Task.async(fn -> :timer.sleep(10) end) |> Task.await(1)
-  end
-
-  defoverridable call: 2
-
-  use Appsignal.Phoenix
 end
 
 defmodule Appsignal.PhoenixTest do
   use ExUnit.Case
   alias Appsignal.FakeTransaction
+  use Plug.Test
 
   setup do
     {:ok, fake_transaction} = FakeTransaction.start_link()

      assert [transaction] == FakeTransaction.finished_transactions(fake_transaction)
      assert [transaction] == FakeTransaction.completed_transactions(fake_transaction)
    end

    test "reports an error for a timeout", %{conn: conn, fake_transaction: fake_transaction} do
      :ok =
        try do
          UsingAppsignalPhoenixWithTimeout.call(conn, %{})
        catch
          :exit, {:timeout, {Task, :await, _}} -> :ok
          type, reason -> {type, reason}
        end

      assert FakeTransaction.started_transaction?(fake_transaction)

      [{%Appsignal.Transaction{} = transaction, name, message, _stack}] =
        FakeTransaction.errors(fake_transaction)

      assert name == ":timeout"
      assert message =~ ~r({:timeout, {Task, :await, \[%Task{owner: ...)

      assert [transaction] == FakeTransaction.finished_transactions(fake_transaction)
      assert [transaction] == FakeTransaction.completed_transactions(fake_transaction)
    end
  end
end


  describe "concerning starting and finishing transactions" do
    setup do
      conn =
        :get
        |> conn("/", "")
        |> PhoenixWithAppSignal.call([])

      [conn: conn]
    end

    test "starts a transaction", %{fake_transaction: fake_transaction} do
      assert FakeTransaction.started_transaction?(fake_transaction)
    end

    test "returns the updated conn", %{conn: conn} do
      assert conn.state == :sent
    end

    test "finishes the transaction", %{fake_transaction: fake_transaction} do
