<commit_before>defmodule Appsignal.Phoenix.InstrumenterTest do
  use ExUnit.Case, async: true
  alias Appsignal.{Phoenix.Instrumenter, Transaction, FakeTransaction}

  setup do
    FakeTransaction.start_link

    transaction = Transaction.start("test", :http_request)

    [transaction: transaction]
  end

  test "starts an event in phoenix_controller_call", context do
    arguments = %{foo: "bar"}
    assert {context[:transaction], arguments} ==
      Instrumenter.phoenix_controller_call(:start, nil, arguments)
  end

  test "sets the action name in phoenix_controller_call", context do
    conn = %Plug.Conn{}
    |> Plug.Conn.put_private(:phoenix_controller, "foo")
    |> Plug.Conn.put_private(:phoenix_action, "bar")

    arguments = %{foo: "bar", conn: conn}
    Instrumenter.phoenix_controller_call(:start, nil, arguments)
    assert "foo#bar" == FakeTransaction.action
  end

  test "starts an event in phoenix_controller_render", context do
    arguments = %{foo: "bar"}
    assert {context[:transaction], arguments} ==
      Instrumenter.phoenix_controller_render(:start, nil, arguments)
  end

  test "finishes an event in phoenix_controller_call", context do
    Instrumenter.phoenix_controller_call(:stop, nil, {context[:transaction], %{conn: %Plug.Conn{}}})
    assert [
      %{<commit_msg>Don't pass unused context in InstrumenterTest<commit_after>defmodule Appsignal.Phoenix.InstrumenterTest do
  use ExUnit.Case, async: true
  alias Appsignal.{Phoenix.Instrumenter, Transaction, FakeTransaction}

  setup do
    FakeTransaction.start_link

    transaction = Transaction.start("test", :http_request)

    [transaction: transaction]
  end

  test "starts an event in phoenix_controller_call", context do
    arguments = %{foo: "bar"}
    assert {context[:transaction], arguments} ==
      Instrumenter.phoenix_controller_call(:start, nil, arguments)
  end

  test "sets the action name in phoenix_controller_call" do
    conn = %Plug.Conn{}
    |> Plug.Conn.put_private(:phoenix_controller, "foo")
    |> Plug.Conn.put_private(:phoenix_action, "bar")

    arguments = %{foo: "bar", conn: conn}
    Instrumenter.phoenix_controller_call(:start, nil, arguments)
    assert "foo#bar" == FakeTransaction.action
  end

  test "starts an event in phoenix_controller_render", context do
    arguments = %{foo: "bar"}
    assert {context[:transaction], arguments} ==
      Instrumenter.phoenix_controller_render(:start, nil, arguments)
  end

  test "finishes an event in phoenix_controller_call", context do
    Instrumenter.phoenix_controller_call(:stop, nil, {context[:transaction], %{conn: %Plug.Conn{}}})
    assert [
      %{
{'fraction_non_alphanumeric': 0.11275066212637155, 'fraction_numerical': 0.0, 'mean_word_length': 4.58985200845666, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, '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': '5506680', 'n_tokens_mistral': 824, 'n_tokens_neox': 797, 'n_words': 198}